Statalist


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

st: dummies from categorical variable


From   Jennifer Baxter <[email protected]>
To   [email protected]
Subject   st: dummies from categorical variable
Date   Mon, 20 Jul 2009 14:06:48 +1000

I have a categorical variable with >200 possible values, but depending on which dataset I use, some of the possible values are not filled. I want to create dummy values from this variable that are the same regardless of which dataset I use, ie that reflect all possible values of that variable.

If I use:

 tab ACTIVITY, gen(ACT),

the dummy variables don't align across datasets because dummies are not created when no respondents report a particular activity.

I could loop over the possible values instead:

foreach act of numlist 1/215 {
qui: gen ACT `act'=(ACTIVITY ==`act')
}

and this works well, except the variable labels aren't then attached to the dummy variables, and I really want them to be.


Is there an alternative to "tab" that I could use, with an option to also create dummies for empty cells? Or, is there a way I can attach variable labels in the loop above based on the value labels of the original variable (as is done in tab xx, gen(xxx)) ?

Thanks,
Jenny



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