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

st: RE: CREATING MUTUALLY EXCLUSIVE MULTILEVEL CATEGORICAL VARIABLE


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: CREATING MUTUALLY EXCLUSIVE MULTILEVEL CATEGORICAL VARIABLE
Date   Mon, 19 Jul 2004 10:13:19 +0100

I am not clear on your data structure. 

One natural data structure would be seem to be to hold 
information on A through F as indicator variables, 1 for has and 
0 for has not condition. 

gen ndiseases = A +  B +  C +  D +  E +  F

counts diseases. Then 

gen status = 0 if ndiseases = 0 

tokenize "A B C D E F" 

forval i = 1/6 { 
	replace status = `i' if ``i'' == 1 & ndiseases == 1 
} 

replace status = 7 if ndiseases > 2 & ndiseases < . 
assert status < 8 

Nick 
[email protected] 

Leonard E. Egede MD, MS
 
> I am trying to create a categorical variable with 8 levels 
> each representing the presence of one of six discrete disease 
> conditions. However, it is possible for subjects to have more 
> than 1 disease condition. How do I create such a multi-level 
> variable so that each level contains only subjects with 1 of 
> the disease conditions and those with multiple disease 
> conditions fall into a level and those with none of the 
> diseases of interest fall into another level?
> 
> I tried the generate and replace commands as shown below but 
> i am uncertain of how stata handles arguments in the replace command
> 
> ***What i have done so far***
> I created a multi-level variable using generate and replace 
> capture discrete medical conditions with 7 categories as follows
> generate disease
> replace disease=2 if medical condition ==A
> replace disease=3 if medical condition ==B
> replace disease=4 if medical condition ==C
> replace disease=5 if medical condition ==D
> replace disease=6 if medical condition ==E
> replace disease=7 if medical condition ==F
> 
> The questions are - is this the right method? if so  how do i 
> code subjects with more than 1 of the conditions above i.e 
> any combinations of A thru F. Also, how does this approach handle
> people with 2 or more of the specified conditions.
> 
> I intend to use the 8 level variable in a logistic model with 
> level 1 (those without diseases of interest) as the reference.

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