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: value labels, rename and merge
From
Maarten buis <[email protected]>
To
[email protected]
Subject
Re: st: value labels, rename and merge
Date
Mon, 12 Apr 2010 06:11:16 -0700 (PDT)
--- On Mon, 12/4/10, Tomas Lind wrote:
> A software for making surveys on the web generates a small
> dataset with variable- and value labels. Variable names are
> generic of the form Q1, Q2, Q3 … .Because many of names are
> already used in a large dataset we rename the variables wQ1,
> wQ2, wQ3 ... before -merge-. When we merge the web dataset
> to the large dataset (merge webdata using largedata) we get
> a note from Stata that “Label already exist Q1” (for a
> number of variables).
>
> Also, when the webdataset is merged to the large dataset,
> value labels in the web-dataset get its text from value
> labels in the large dataset. This applies to all variables
> that shared the same name before being renamed. For example
> value labels for wQ2 (a question about age) has value labels
> for Q2 (a question about food).
You will have to change the name of the value labels manually.
You can change all variable names and the associated value
label names using a loop like in the example below:
*------------- begin example ----------------
sysuse nlsw88, clear
desc
foreach var of varlist _all {
rename `var' w_`var'
local lab : value label w_`var'
if "`lab'" != "" {
label copy `lab' w_`lab'
label drop `lab'
label values w_`var' w_`lab'
}
}
desc
*-------------- end example -----------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )
hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/