Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: stack time-series to paneldata


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: stack time-series to paneldata
Date   Thu, 12 May 2011 09:10:43 +0100

This is not intemediate between -stack- and -reshape-. It is a
standard application of either, subject to a documented trick. I
recommend using -reshape- as the more versatile command. Examples very
like yours have appeared in very recent threads on this list.

ds Year, not

foreach v in `r(varlist)' {
    rename `v'  Women`v'
}

reshape long Women , i(Year) j(ID) string

The only tricky bit about your example is that your variable names do
not start with a common stub, so you just supply one. See also

FAQ     . . . . . . . . . . . . . . . . . . . . . . . .  Problems with reshape
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        12/03   I am having problems with the reshape command. Can
                you give further guidance?
                http://www.stata.com/support/faqs/data/reshape3.html

Nick

On Wed, May 11, 2011 at 8:24 PM, Max Roser <gitarrenmax@googlemail.com> wrote:

> I have a small question concerning the input of data.
> I want to stack Time-series to get a paneldata set.
> So what I'd need is something between the stack and the reshape commands.
>
> To clarify. I have data like this
>
> Year    USA    UK    Brasil
>
> 2000    12    12    15
> 2001    13    12    14
> 2002    14    13    13
>
> and I want
>
> ID        Year        Women
>
> USA    2000        12
> USA    2001        13
> USA    2002        14
> UK    2000        12
> UK    2001        12
> UK    2002        13
> Brazil    2000    15
> Brazil    2001    14
> Brazil    2002    13
>
> Does anyone have an idea of how to do that?
> (I always make as many year-variables as countries and then stack the
> data. Obviously its prone to errors and very unelegant)
> I need:
> take countries as ids and stack them into year and join the value to id
> &  year
>
> Using Stata/IC 10.1 Born June 2010 (for Windows)
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index