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

Re: st: simple question

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

--- Sebastián Daza <> wrote:
> I need to create dummy or indicator variables (0,1) for a period
> variable (years, age) with the following format:
> 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 )

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

*   For searches and help try:

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