Statalist


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

Re: st: dummies from categorical variable


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: dummies from categorical variable
Date   Mon, 20 Jul 2009 06:12:11 +0000 (GMT)

--- On Mon, 20/7/09, Jennifer Baxter <Jennifer.Baxter@aifs.gov.au> wrote:
<snip>
> 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.
<snip>

You can just add the variable labels in the loop, 
using the -label- command.

Additionally, I would extend your -generate- command 
in two ways:

1) I would make sure that your dummies maintain the
missing values that may or may not be present in the 
original variable by adding -if !missing(varname)-

2) If you make that many dummies it pays to 
immediately create them as -bytes- to save memory.

*---------------- begin example ------------------
sysuse auto, clear
forvalues act = 1/5 {
	qui gen byte act`act' = rep78 == `act' ///
                                if !missing(rep78)
	label var act`act' "rep78 == `act'"
}
desc act*
*------------------ end example ------------------

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      

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