Statalist The Stata Listserver


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

st: RE: value labels


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: value labels
Date   Thu, 18 May 2006 21:55:18 +0100

What you have done wrong is confuse
two distinct ideas. Assigning value 
labels to a numeric variable doesn't
mean that it becomes a string variable. 

list var2 if sex == "male" 

is legal if and only if -sex- is a string 
variable. But it is still a numeric 
variable. 

There is a way to do what you want. 
It is documented at [U] 13.9 (guessing, 
can't find my copy at this moment) and in

SJ-4-4  dm0009  . . . . . . .  Stata tip 14: Using value labels in expressions
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  K. Higbee
        Q4/04   SJ 4(4):486--487                                 (no commands)
        tips for using value labels in expressions

The way is 

list var2 if sex == "male":lab_sex

In other words, you can do this so long as you _also_
specify the labelname. The usefulness of this is emphasised
in the places cited. On the other hand, you might 
decide just to do it all the old way. Or, yet again, 
you might prefer to -decode- (but note the storage
implications).  	
 
Nick 
n.j.cox@durham.ac.uk 

Raoul C Reulen
  
> I am trying to define value labels for a variable called 'sex'.
>  
> . label define lab_sex 1 male 2 female
> . label values sex lab_sex
>  
> However, now I want to list a different variable according to 
> the value label like this:
>  
> .list var2 if sex=="male"
>  
> but that gives me an error message, but:
>  
> .list var2 if sex==1
>  
> works. What have I done wrong?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index