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

Re: st: Macros and dummy variables


From   Seb Buechte <[email protected]>
To   [email protected]
Subject   Re: st: Macros and dummy variables
Date   Thu, 27 Oct 2005 10:46:32 +0200

Ilaria,

since you have one variable from which all the dummies are to be
created there are two ways how you could do it:

Instead of

gen dummy1=1 if nearesthospital==1
gen dummy2=1 if nearesthospital==1
...

// You could do:

gen dummy=1
separate dummy, by(nearesthospital)
drop dummy

// If you would like dummy variables that contain ones and zeros you should do:

tabulate nearesthospital, generate(dummy)

// Kind regards, sebastian!



On 10/27/05, Mosca, Ilaria <[email protected]> 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index