Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Reshaping data question


From   "Scott Merryman" <[email protected]>
To   [email protected]
Subject   Re: st: Reshaping data question
Date   Tue, 8 Apr 2008 04:27:34 -0500

Here one way:

clear
input str10 country str10 data     yr1960  yr1961  yr1962
Argentina               GDP                     5
 7                       9
Argentina               Population              10
 8                       5
Brazil                  GDP                     1
 9                       10
Brazil                  Population              5
 35                      12
end

reshape long yr , j(year) i(country data)
reshape wide yr  ,j(data)  i(country year )  string
renpfix yr
l, ab(12) sepby(cou)

Scott


On Mon, Apr 7, 2008 at 9:27 PM, Glenn Hoetker <[email protected]> wrote:
>
>
> I have data in a layout that is new to me and I'm stuck on how to reshape it
> to what I need.  Worse, I feel like I'm missing something obvious.  Any help
> would be much appreciated.
>
> The data is in this layout (with fictional data)
>
> COUNTRY DATA_SERIES     YR1960  YR1961  YR1962
> Argentina               GDP                     5                       7
> 9
> Argentina               Population              10                      8
> 5
> Brazil                  GDP                     1                       9
> 10
> Brazil                  Population              5                       35
> 12
>
> I would like to get it into this format:
>
> COUNTRY                 YEAR            GDP             POPULATION
> Argentina               1960            5                               10
> Argentina               1961            7                               8
> ...
> Brazil                  1960            1                               5
> Brazil                  1961            9                               35
> etc.
>
> It's the "DATA_SERIES"  variable in the original data that is really
> throwing me.  I'm fairly comfortable with plain vanilla "reshape".  Thank
> you in advance for any help.
>
> Glenn Hoetker
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index