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