Statalist


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

st: AW: dummies from categorical variable


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
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.




HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Jennifer Baxter
Gesendet: Montag, 20. Juli 2009 06:07
An: [email protected]
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)) ?

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/


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