Statalist


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

Re: st: Reshaping


From   Neil Shephard <nshephard@nhs.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Reshaping
Date   Tue, 11 Nov 2008 10:16:17 +0000

Pavlos C. Symeou wrote:
> Dear Statalisters,
>
> I have panel data in the following format (actually yearly data extend
> up to year_2007):
>
> Country     measure     year_1990     year_1991     year_1992    
> year_1993 year_1994     year_1995
> Argentina     gdp_constant     182,63     201,81     222,59    
> 236,51     250,31     243,19
> Argentina     gdp_deflator     37,74     89,64     101,82     100    
> 102,85     106,11
> Argentina     gdp_percap_const     5614,3     6120,91     6660,41    
> 6972,96 7286,34     6992,31
> Argentina     gdp_percap_current     4344,82     5750,51    
> 6845,48     6972,96   7493,95     7419,16
> Argentina     gdp_ppp     182,37     208,56     235,33     255,81    
> 276,5     274,13
> Argentina     gdp_ppp_percap     5606,06     6325,71     7041,58    
> 7542,26 8048,73 7881,97
> Argentina     ppp_conversion_rate     0,38     0,87     0,96    
> 0,93     0,93     0,94
> Argentina     cpi     23,21     63,05     78,75     93,33    
> 97,23     100,52
> Argentina     population     32,53     32,97     33,42     33,92    
> 34,35     34,78
> Australia     gdp_constant     581,27     574,22     586,19    
> 608,95     640,25     663,04
> Australia     gdp_deflator     70     71,54     72,71     73,6    
> 74,16     75,49
> Australia     gdp_percap_const     34011,52     33167,52    
> 33462,01     34411,12 35799,96 36624,29
> Australia     gdp_percap_current     18601,81     18486,94    
> 17889,14 17225,66 19424,37 20499,27
> Australia     gdp_ppp     299,35     306,06     319,63     339,71    
> 364,76     385,47
> Australia     gdp_ppp_percap     17515,56     17678,38    
> 18245,57     19196,38 20395,62     21292,13
> Australia     ppp_conversion_rate     1,36     1,34     1,33    
> 1,32     1,3     1,3
> Australia     cpi     80,35     82,94     83,76     85,28     86,9    
> 90,93
> Australia     population     17,09     17,31     17,52     17,7    
> 17,88     18,1
>
>
>
> I need to reshape them in the following format:
>
> Country        year   gdp_constant   gdp_deflator gdp_percap_const  
> gdp_percap_current   gdp_ppp  gdp_ppp_percap ppp_conversion_rate cpi  
> population
> Argentina   1990
> Argentina   1991
> Argentina   1992
> Argentina   1993
> Argentina   1994
> Argentina   1995
> Australia    1990
> Australia    1991
> Australia    1992
> Australia    1993
> Australia    1994
> Australia    1995
>
> Can you please help?

I could be obtuse and simply say read -man reshape- and you would do
well to do so as without understanding how the command works you will
continue to rely on others to help you with the solution.

The following should do what you want though...

reshape long year_, i(Country measure) j(year)
reshape wide year_, i(Country year) j(measure) string
/* Optionally rename using -renvars- from ssc, if not installed -ssc
inst renvars- */
renvars year_*, presub("year_" "")

You can probably achieve the same results using -xpose- but its slightly
more tricky as you would have to loop over each country appending the
resulting datasets into one large one.

Neil

-- 
"We should make things as simple as possible, but not simpler" - Anon (not Albert Einstein)


***********************************************************************
This  message  may  contain  confidential and  privileged  information.
If you  are not the  intended recipient  you should not  disclose, copy
or distribute information in this e-mail or take any action in reliance
on its contents.  To do so is strictly  prohibited and may be unlawful.
Please  inform  the  sender that  this  message has  gone astray before
deleting it.  Thank you.

2008 marks the 60th anniversary of the NHS.  It's an opportunity to pay
tribute to the NHS staff and volunteers who help shape the service, and
celebrate their achievements.

If you work for the NHS  and  would like  an NHSmail  email account, go
to: www.connectingforhealth.nhs.uk/nhsmail
***********************************************************************

*
*   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   |   What's new   |   Site index