Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SV: st: value labels, rename and merge

From   "Tomas Lind" <>
To   <>
Subject   SV: st: value labels, rename and merge
Date   Mon, 12 Apr 2010 16:02:13 +0200

I´ll try your syntax tomorrow (it seems promising). 
What happens when
local lab : value label w_`var'
is executed?


-----Ursprungligt meddelande-----
[] För Maarten buis
Skickat: den 12 april 2010 15:11
Ämne: Re: st: value labels, rename and merge

--- 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
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' 
*-------------- end example -----------------
(For more on examples I sent to the Statalist see: )

hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen


*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index