Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: reshape


From   baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: reshape
Date   Tue, 17 Sep 2002 08:28:12 -0400

--On Tuesday, September 17, 2002 2:33 -0400 Alejandro wrote:

Hi, i have the a database like this:

country         descriptor      year1970 year1971 ... year2000
Argentina          var1                x70          x71              x00
Argentina          var2                y70          y71              y00
Bolivia               var1                x70         x71
x00 Bolivia               var2                y70         y71
y00 .
.
.

and so on... i want to know if exists a way in which i could reshape this
wide dataset into a long one that would look like this:

country         year           var1           var2
Argentina       1970            x70            y70
Argentina       1971            x71            y71
    .
    .
    .
 do you know how could i do the reshape of the two variables jointly ? if
i use the <reshape> command i'd have to do it one by one.

. list

cty var d1970 d1971 d1972
1. arg var1 1970 1971 1972
2. arg var2 2070 2071 2072
3. bol var1 2170 2171 2172
4. bol var2 2270 2271 2272

. reshape long d ,i(cty var)

. rename _j year

. reshape wide d,i(cty year) j(var) string


. list

cty year dvar1 dvar2
1. arg 1970 1970 2070
2. arg 1971 1971 2071
3. arg 1972 1972 2072
4. bol 1970 2170 2270
5. bol 1971 2171 2271
6. bol 1972 2172 2272


There is always a way to do it with reshape. The difficulty is figuring out how!

Kit

*
* 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index