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: Suggestion for Reshape


From   "Dimitriy V. Masterov" <dvmaster@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Suggestion for Reshape
Date   Fri, 17 Sep 2010 10:24:30 -0400

Assuming your variables were country and year1-year9, I was going to
suggest a stack followed by reshape wide:

bys country: gen var=_n

stack var country year1 var country year2 var country year3 var
country year4 var country year5 var country year6 var country year7
var country year8 var country year9, into(var country x) clear

rename _stack year

reshape wide x, i(country year) j(var)

Anders' solution is much more elegant:

bys country: gen var=_n
reshape long year, i(country var)
rename year x
rename _j year
reshape wide x, i(country year) j(var)
*
*   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