Statalist The Stata Listserver


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

st: RE: label


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: label
Date   Fri, 7 Jul 2006 12:39:25 +0100

Strictly, you can't do this, in the sense of 
applying different value labels to any given 
value of a particular variable. 

What you can do is -generate- a string variable 
and its values can be as arbitrary as you like. 

gen mycatlabel = "" 
replace mycatlabel = "A" if group == 1 & cat == 1 
replace mycatlabel = "B" if group == 1 & cat == 2 

What you could also do is form a composite variable: 

egen catgroup = group(cat group) 
label def catgroup 1 "A" 2 "B" ... 
label val catgroup catgroup 

To check what the mapping should be, you 
might find -groups- from SSC useful. A sequence 
could be 

egen catgroup = group(cat group) 
ssc inst groups, replace 
groups catgroup cat group 

and then work out what the labels should be.  

Nick 
n.j.cox@durham.ac.uk 

Patricia Vera Rojas
 
> group  cat
> 1       1
> 1       1
> 1       2
> 1       2
> 2       1
> 2       1
> 2       2
> 3       1
> 3       2
> 
> I want to label "cat" in this way : I want to 
> label cat=1 by "A" if group=1 and by "B" if cat has the
> same value (cat=1) but if group=2.

*
*   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