Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Macros and dummy variables


From   Richard Goldstein <richgold@ix.netcom.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Macros and dummy variables
Date   Thu, 27 Oct 2005 08:38:34 -0400

First, note that the code you show will not give you dummy variables -- rather it will give you variables with values of 1 if meets the condition and missing otherwise.

The easiest solution for what you show is to use tabulate with the gen() option.

If you want to use the type of code you show, use -forval-:
forval i=1/40 {
gen dummy`i'=nearesthospital==`i'
}

Rich

Mosca, Ilaria wrote:

Dear Statalisters,

I have the following dummies gen dummy1 = 1 if nearesthospital ==1
gen dummy2 = 1 if nearesthospital ==2
gen dummy3 = 1 if nearesthospital ==3
gen dummy4 = 1 if nearesthospital ==4
gen dummy5 = 1 if nearesthospital ==5
Etc. etc.

The number of dummies that have to be generated are up to 40 or more. I
was thus thinking of creating a local macro for generating the dummies
and avoiding typing the commands every single time. I read the macro
section on the Stata User's Guide, but unfortunately cannot see how to
apply the explanations to the above-mentioned case. Any idea?

Thank you very much,
Ilaria
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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