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

st: RE: Re: reshape ,string has its limitations

From   baum <>
To   "Riano, Alejandro" <>
Subject   st: RE: Re: reshape ,string has its limitations
Date   Tue, 17 Sep 2002 14:46:17 -0400



It is indeed the case that the second reshape will fail in that instance to do anything sensible, since it finds multiple words rather than unique string values in the 'j' variable.

I think the answer to this lies in Nick Cox' latest 'Speaking Stata' column. You need to use 'encode' to change 'var' into a numeric variable with its string values as value labels. This will then do the second reshape properly. I do not have time now to experiment with it, but when you have done that second reshape, you will have variables that have numeric tags. At that point you can apply sensible variable names. The real issue here is that a name like 'Total factor productivity' is not a legal Stata variable name; 'TFP' or 'TotalFactorProductivity' would be.


--On Tuesday, September 17, 2002 11:52 -0400 "Riano, Alejandro" <> wrote:

Hi, Kit your procedure for my reshape problem works almost perfect, the
thing is that my descriptor usually is a very long string such as "Total
factor Productivity" and when i do

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

i'll lose my variables column as i get:

(note: j = Total factor productivity Volume of non-oil imports)
(note: no data for descriptor == Total)
(note: no data for descriptor == factor)
(note: no data for descriptor == productivity)

I ended up with only country year columns.

The second problem is that the number of series is very large (about 170)
and most of them are not available for all countries, which make coding
very messy. I'd really appreciate your help on this,

thank you

-----Original Message-----
From: baum []
Sent: Tuesday, September 17, 2002 8:28 AM
Subject: st: Re: reshape

--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!


*   For searches and help try:

*   For searches and help try:

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