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: Renaming all value labels in a dataset

From   Maarten Buis <>
Subject   Re: st: Renaming all value labels in a dataset
Date   Thu, 23 Aug 2012 12:37:37 +0200

On Thu, Aug 23, 2012 at 12:21 PM, Mark McCann wrote:
>                 I'm having some problems with Stata SE 12.1 (and Stat-Transfer 10) in terms of merging files. I have several files that have been StatTransferred into Stata files, and the variables labels are auto-labelled LABA, LABB, LABC etc.
> A problem occurs when these files are merged together, as LABA in file1.dta and file2.dta refer to different values.
> Is there any way to rename all the value labels in a dataset with a prefix?

*--------------------- begin example ----------------------
sysuse nlsw88, clear

// see current label names

// get all variables with value labels
ds, has(vallabel)
local vars `r(varlist)'

foreach var of local vars {
	// get the name of the value label for variable `var'
	local labname : value label `var'
	// create a copy with name prefix + oldname
	label copy `labname' foo_`labname', replace
	// assign that copy to variable `var'
	label value `var' foo_`labname'

// see the new label names
*---------------------- end example -----------------------
(For more on examples I sent to the Statalist see: )

Hope this helps,

Maarten L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:

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