Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: variable labels lost due to reshape


From   Joseph Coveney <jcoveney@bigplanet.com>
To   Statalist <statalist@hsphsun2.harvard.edu>
Subject   Re: st: variable labels lost due to reshape
Date   Wed, 14 Jun 2006 11:44:19 +0900

Ada Ma wrote:

All the info you needed are actually in the help file for label.

After you have collapsed the data, the labels should still be
available.  You can check that by typing:

label dir

to check if the labels you used are still hanging around.  If they do,
you'd only need to attach them to the new variables you have created.
If you're unsure what are in each of the labels, say if you have a
label called jelena, you can type:

label list jelena

You can also write

label save using child

which would save all the labellings into a do file.   Even if the
labels are for whatever reason lost you can run the label save command
with your child dataset loaded up and then when you have your altered
data set loaded up or your mother data set loaded up, you just run the
do file to make the labels available again. You shouldn't need to do
what Joseph Coveney recommended.

--------------------------------------------------------------------------------

You might have got confused by the do-file that I attached.  Jelena Zurovac
wasn't asking about keeping value labels, but rather about keeping variable
labels.

To keep variable labels, you put them into a macro using the
extended-function macro "`: variable label [variable name]'.

Because I was reshaping long, I re-applied the variable labels as value
labels to the j() variable that is created by -reshape long-.*  But that was
just for illustration.  Once you have put the variable labels into macros,
you can do whatever you like with them.  The illustration below sticks with
variable labels re-applied as variable labels, and so might be less
confusing.

Joseph Coveney

*You can go both ways--see the same help file for capturing a set of value
labels as extended-function macros, which you can then re-apply as variable
labels after reshaping wide.

clear
set more off
set obs 1
generate byte first_variable = 1
label variable first_variable "This is really neat!"
forvalues i = 1/10 {
   generate byte next_variable`i' = 1
}
describe, fullnames
*
* Here we go
*
local variable_label : variable label first_variable // <-here
foreach var of varlist next_* {
   label variable `var' "`variable_label'"
}
describe, fullnames
exit

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