Statalist


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

Re: st: an egen command


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: an egen command
Date   Tue, 16 Feb 2010 09:14:37 +0000 (GMT)

--- On Tue, 16/2/10, Jet wrote:
> I am using egen to create new variables. Basically, I want to
> recode a continuous variable into two groups, below or above
> the mean.

Here are three different ways of achieving this goal:

*--------------- begin example ------------
sysuse auto, clear
sum mpg
gen byte d_mpg1 = mpg > r(mean) if mpg < .

gen byte d_mpg2 = 1 if mpg > r(mean) & mpg < .
replace d_mpg2 = 0 if mpg <= r(mean) & mpg < .

gen byte d_mpg3 = cond(mpg > r(mean), 1, 0) if mpg < .
*---------------- end example --------------
( For more on how to use examples I sent to statalist see:
 http://www.maartenbuis.nl/stata/exampleFAQ.html )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

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