Bookmark and Share

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


[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 <[email protected]>
To   [email protected]
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 <http://www.stata.com/statalist/archive/2012-05/msg01298.html>

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.

Nick

On Sat, Jun 2, 2012 at 9:47 AM, Paul O'Brien <[email protected]> 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:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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