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]

Re: st: How to apply a command to numeric variables only

From   Nick Cox <>
Subject   Re: st: How to apply a command to numeric variables only
Date   Sat, 2 Jun 2012 10:50:50 +0100

That's already been answered by me in this thread.

See <>

Before you might lose it, you save the variable label of -oldvar- by

  local varlabel : variable label oldvar

and later you apply that to -newvar- by

label var newvar "`varlabel'"

You need to apply that to whatever code you ended up using.


On Sat, Jun 2, 2012 at 9:47 AM, Paul O'Brien <> wrote:
> That's great Nick, thanks.
> The last thing is to restore the variable labels, which are lost in the new variables.
> The labels were 'SRH Care Activity 4', 'SRH Care Activity 5' and 'SRH Care Activity 6', although in another dataset the number of variables I have to decode could be between 2 and 4.
> Is there a way to remember the labels and reapply them to the new variables?
> Paul
> On 30 May 2012, at 00:57, Nick Cox wrote:
>> Your problem was posed that you want to -decode- variables, except
>> that you can't -decode- string variables. But you can't -decode-
>> variables without value labels either. So let's suppose you just want
>> a string version.
>> foreach var in `r(varlist)' {
>>         capture decode `var', generate(work)
>>         if _rc gen work = string(`var')
>>         drop `var'
>>         rename work `var'
>> }

*   For searches and help try:

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