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]

st: reshape and value labels


From   Leandro Brufman <[email protected]>
To   [email protected]
Subject   st: reshape and value labels
Date   Mon, 22 Aug 2011 23:09:27 -0400

Hello list.
I'm using Stata 10.1 and I have a dataset (that comes from an Excel
file through an insheet) that looks like this:

Date,    Var1,    Var2,    Var3
2001m1,    98,    34,    23
2001m2,    94,    33,    25

where the commas are just separating the different columns, and Var1,
Var2, Var3 are actually pretty long pieces of string like:
coffeearabicacentskgcurrent with a variable label "Coffee, Arabica,
cents/kg, current" or  crudeoilbrendtbblcurrent with a variable label
"Crude oil, Brendt, $/bbl, current", and the numbers are just prices.

I would like to make it look like this:
Date, Name, Price
2001m1, Var1, 98
2001m2, Var1, 94
2001m1, Var2, 34
2001m2, Var2, 33
2001m1, Var3, 23
2001m2, Var3, 25

where again, Var1, Var2, Var3 are the variable labels of Var1, Var2,
Var3. (so that later on I can encode it and have a nice and neat
dataset).

Now, I managed to do the "reshape long, string" (small digression: to
do the reshape I usually rename all the vars to include a prefix to
use as stub in the reshape long stub, i() j() string" command. That
renaming encounters the string length limit for varnames and I solved
it using abbrev() function. I found it a little cumbersome, maybe
there's an easier way), but I lose the variable label. I thought of
saving it into a local (following this thread
http://www.stata.com/support/faqs/data/labels_reshape.html), but in
the implementation part afterwards I got stuck. I would like to use
the variable labels as value labels. I also thought about doing a
replace (ie.  replace name="var1label" if name=="var1"), but also I'm
not entirely sure how to implement it.

Any ideas?
Thank you so much!
*
*   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