Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: value labels, rename and merge

From   Maarten buis <>
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
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:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index