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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Renaming all value labels in a dataset


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Renaming all value labels in a dataset
Date   Thu, 23 Aug 2012 11:36:54 +0100

Although "variable labels" and "value labels" are both mentioned here,
I am going to answer in terms of variable labels. Suppose you have one
dataset, file1.dta. You can re-label all variables like this

foreach v of var * {
       local lbl : var label `v'
       label var `v'  "file1: `lbl'"
}

If label length bites, you may need something more like this

foreach v of var * {
       local lbl : var label `v'
       local new = substr("file1: `lbl'", 1, 32)
       label var `v'  "`new'"
}

On Thu, Aug 23, 2012 at 11:21 AM, Mark McCann <mark.mccann@qub.ac.uk> 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? Alternatively, is there a way to prefix value labels in StatTransfer? I was unable to find any advice in the help files beyond dropping and recreating variables, which given the number of files and variables would be very time consuming. Any advice on a faster process would be much appreciated.

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


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