Statalist


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

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


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Converting a continuous var into a binary var
Date   Mon, 6 Jul 2009 21:14:14 +0200

<>

***
clear*
set obs 10000

gen x= rnormal()

//introduce random missings
replace x=. if runiform()<0.05

_pctile x, p(10)

gen byte y = !mi(x) & x>r(r1)

/*
check
*/

table y, /*
*/contents(min x mean x max x freq) row
***



HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Pancho Villa
Sent: Montag, 6. Juli 2009 20:45
To: statalist@hsphsun2.harvard.edu
Subject: st: Converting a continuous var into a binary var

Hi,

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.

Please help.

Thanks in advance,

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

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index