Statalist


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

st: RE: Converting a continuous var into a binary var


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Converting a continuous var into a binary var
Date   Mon, 6 Jul 2009 19:50:42 +0100

Your boss just emailed me that he's not impressed by this post, as he
realises that you won't deserve any credit for a solution. Nevertheless
consider this: 

su x, detail 
gen y = x > r(p10) if x < . 

Nick 
[email protected] 

Pancho Villa

It couldn't get more basic than this.  I'm creating a binary variable
y.  The criteria for y to be equal to one is that the value of x is
greater than its 10th percentile value.  Otherwise it'll be zero.

So I tried to this, but it didn't work:

********************************
gen y=0
replace y=1 if x>p10(x)
********************************

Now, I know I can collapse x and get p10 that way, and then use the
p10 value to create y.  But I want something just a tiny bit more
elegant to impress my boss.


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