Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Code to generate dummy variable from several categorical variables?


From   "DEBORAH L. HUANG" <[email protected]>
To   [email protected]
Subject   Re: st: Code to generate dummy variable from several categorical variables?
Date   Tue, 17 Jan 2012 11:39:53 -0800 (PST)

Basically what I'm hoping to do is "collapse" the outcome variables A, B and C (all binary) into the new outcome indicator variable abnlX for ANOVA (e.g., comparison mean age across indicators, among other continuous demographic variables).

The new outcome variable abnlX would have 3 indicators (my mistake in the earlier message). As an indicator variable abnlX would be defined as follows:

abnlX indicator #1 =0 if A is 0 or missing, B is 0/1/missing, C is 0/1/missing; =1 if A is 1, B is 0/1/missing, C is 0/1/missing
abnlX indicator #2 =0 if B is 0 or missing, A is 0/1/missing, C is 0/1/missing; =1 if B is 1, A is 0/1/missing, C is 0/1/missing
abnlX indicator #3 =0 if C is 0 or missing, A is 0/1/missing, B is 0/1/missing; =1 if C is 1, A is 0/1/missing, C is 0/1/missing

Alternately for a categorical outcome variable abnlX it would be defined as follows:
abnlX=0 if A=0 or missing & B=0 or missing & C=0 or missing
abnlX=1 if A=1 & B=0/1/missing & C=0/1/missing
abnlX=2 if B=1 & A=0/1/missing & C=0/1/missing
abnlX=3 if C=1 & A=0/1/missing & B=0/1/missing

Thank you again to everyone for your input, and hopefully this further clarifies my question.

Deborah Huang

On Tue, Jan 17, 2012 at 7:22 AM, David Hoaglin <[email protected]> wrote:

It would help to have further clarification.

As Nick pointed out, an indicator variable (aka dummy variable) has two (non-missing) >values: 0 and 1.  Please explain what you mean by "a dummy variable with 4 indicators" and >then give an explicit definition of the desired "dummy variable" in terms of A, B, and C.

If you actually want a categorical variable with 4 categories (which would necessarily be >mutually exclusive), please define those categories in terms of A, B, and C.

Your explanation of the "dummy variable" abnlX lists three indicator variables.  If you >intend abnlX to be a categorical variable, those three indicators are not mutually exclusive.

It would help if you described the role that the new variable will play in an analysis.  >Some regression models, for example, could include the binary variables A, B, and C as they >stand; they would not need to be mutually exclusive.

BTW, three binary variables yield 8 possible combinations.  The one not in your list is A=1, >B=0, C=1.  Why is it necessary to re-categorize this subject and subjects #2, #3, and #5?

David Hoaglin


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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