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: How to apply a command to numeric variables only

From   "Paul O'Brien" <>
Subject   Re: st: How to apply a command to numeric variables only
Date   Sat, 2 Jun 2012 09:47:44 +0100

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?


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'
> }

Dr Paul O'Brien
Raymede Clinic
Westside Contraception and Sexual Health Services
Central London Community Healthcare
Exmoor St
W10 6DZ
+44 (0)20 8962 4450

*   For searches and help try:

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