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

st: AW: dummies from categorical variable

From   "Martin Weiss" <>
To   <>
Subject   st: AW: dummies from categorical variable
Date   Mon, 20 Jul 2009 09:25:02 +0200


Note that -help foreach- toward the bottom says that "foreach must store the
list of elements, whereas forvalues obtains the elements one at a time by
calculation." So your loop would be faster with -forvalues-. Also note you
can attach the -qui- prefix to the -forvalues- command itself.


-----Ursprüngliche Nachricht-----
[] Im Auftrag von Jennifer Baxter
Gesendet: Montag, 20. Juli 2009 06:07
Betreff: st: dummies from categorical variable

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)) ?


*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index