--- On Mon, 20/7/09, Jennifer Baxter <[email protected]> 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/