Statalist


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

Re: st: simple question


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: simple question
Date   Tue, 23 Dec 2008 12:58:59 +0000 (GMT)

--- Sebastián Daza <[email protected]> wrote:
> I need to create dummy or indicator variables (0,1) for a period
> variable (years, age) with the following format:
<snip>
> It's important that the name of the variable has the age name. When I
> use command tab gen, the name of the variable doesn't match with the
> age name (age 4 = d4).

*----------- begin example ------------------
sysuse auto, clear
levelsof mpg
foreach lev in `r(levels)' {
	gen d`lev' = mpg == `lev'
	assert mpg == `lev' if d`lev' == 1
}
*------------- end example ------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Notice that this example will only work if the values of mpg (or age or
year, etc) are integers because otherwise (some of) the variable names
of the dummies will contain a period, which is not allowed.

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room N515

+31 20 5986715

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