Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: rename variables with label values


From   "Eva Poen" <[email protected]>
To   [email protected]
Subject   Re: st: rename variables with label values
Date   Fri, 8 Aug 2008 21:30:45 +0100

Daphna,

you can use a macro inside a loop, like this:

foreach v of varlist var1 var2 var3 {
   local x : variable label `v'
   rename `v' `x'
}

The procedure requires the labels to be valid (and unique) Stata names.
I recommend that you put the original names back as labels, in case
you want to undo it later:

foreach v of varlist var1 var2 var3 {
   local x : variable label `v'
   rename `v' `x'
   label variable `x' "`v'"
}

Hope this helps,
Eva


2008/8/8 daphna bassok <[email protected]>:
> Hi-
>
> I have a strange data cleaning question and was hoping someone would have a
> solution.
>
> Is it possible to rename a list of variables with their label value (meaning
> replace the variable name with the variable label)?  My labels identify the
> item numbers on a particular survey (but my actual variable names are not
> too informative). I am looking for a command like renvars, that will allow
> me quickly rename the variable, but so far I have not been able to find
> something.
>
> Thanks in advance for any advice.
> Daphna
>
> *
> *   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/
>
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index