Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Suggestion for Reshape


From   "Dimitriy V. Masterov" <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index