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

st: Re: dummies from continuous variable


From   baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: dummies from continuous variable
Date   Thu, 15 Aug 2002 08:46:09 -0400

--On Thursday, August 15, 2002 2:33 -0400 Deborah wrote:

In STATA, however, the only way I know to create the same variable is to =
use gen:

gen age2534 =3D (age>=3D25 & age < 35)

Question:  Is there a better way to generate indicator variables from =
continuous ones?
A thread earlier this week spoke about doing this from the percentiles of the continuous variable (pctile, xtile, _pctile). But if you have arbitrary values where you want to bracket the c.v., these two commands will do it:

. gen brackets=recode(mpg,14,18,23,29,35)

. tab brackets, gen(mpgdumm)

brackets | Freq. Percent Cum.
------------+-----------------------------------
14 | 8 10.81 10.81
18 | 19 25.68 36.49
23 | 24 32.43 68.92
29 | 16 21.62 90.54
35 | 7 9.46 100.00
------------+-----------------------------------
Total | 74 100.00


. summ mpgdumm*

Variable | Obs Mean Std. Dev. Min Max
-------------+-----------------------------------------------------
mpgdumm1 | 74 .1081081 .3126365 0 1
mpgdumm2 | 74 .2567568 .439826 0 1
mpgdumm3 | 74 .3243243 .4713172 0 1
mpgdumm4 | 74 .2162162 .4144734 0 1
mpgdumm5 | 74 .0945946 .2946518 0 1

And if you want to apply the same cut-points to a number of variables:


. local brack "14,18,23,29,35"

. g brack2=recode(mpg,`brack')

Kit


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