Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: labels created from -egen ..., group()-


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: labels created from -egen ..., group()-
Date   Mon, 29 Nov 2004 17:12:58 -0000

Let's imagine indicators 

a b c d e f g h i j 

Start with an empty string variable: 

gen Group = "" 

Loop over the indicators: 

qui foreach v of var a b c d e f g h i j { 
	replace Group = Group + cond(`v', "`v'", "") 
} 

Now feed that to 

egen group = group(Group), label 

Nick 
[email protected] 

Daniel Egan
 
> I have about 10 indicators for medical conditions that I am using. I
> used -egen..., group()- to allow myself to track coincidence.
> 
> I would like to have the labels of the -egen-ed variable have labels
> noting what group it belongs to. I therefore created labels for each
> of the indicators akin to
> lab def av 1 "a=1" 0 "a=0"
> lab def bv 1 "b=1" 0 "b=0"
> ....which creates groups of
> group(1) "a=1 b=0"
> group(2) "a=0 b=0"
> group(3) "a=1 b=1"
> 
> However, since there are >=10 of them, the grouped variable value
> label is too large to read.
> 
> So finally, my question is how would I go about having the indicator
> variable name occur in the group label if it the indicator were 1, but
> not otherwise?
> 
> If I understand correctly, a consistent -sort- before -egen...,
> group()- should allow me to write labels out, but I would still need
> to go through and check  if/when groups do/don't occur at all.
> 

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index