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

From |
Howard Lempel <HLempel@brookings.edu> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

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

Date |
Mon, 6 Jul 2009 16:24:59 -0400 |

A mistake below: gen y=rnormal() should be gen z=rnormal() -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Howard Lempel Sent: Monday, July 06, 2009 4:22 PM To: statalist@hsphsun2.harvard.edu Subject: RE: st: RE: Converting a continuous var into a binary var Expanding on Martin's example, I think you want something like this: **** Start Code **** clear* set obs 10000 gen x=rnormal() gen y=rnormal() centile x, ce(10) local x10 = r(c_1) centile z, ce(10) local z10 = r(c_1) gen y = 0 if x<=`x10' & z<=`z10' replace y = 1 if x<=`x10' & z>`z10' *etc. ****** End Code ****** The lines starting with -local- save the results from the -centile- command as locals. These locals can then be accessed by typing `localname'. Notice the left tick and right tick at the beginning and end of the reference to localname. Hope this helps. Howie -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Pancho Villa Sent: Monday, July 06, 2009 4:01 PM To: statalist@hsphsun2.harvard.edu Subject: Re: st: RE: Converting a continuous var into a binary var Thank you, Nick and Martin. I abbreviated my problem for simplicity. So much that I'm afraid the feedback I got from you is not helping me much. Actually, my variable y is not binary, but categorical with more than 2 possible values. My y depends on the 10th percentile values of x and z, respectively. (In fact, it depends on the values of other variables, but that's not problematic. This is the simplest description of my problem that can get me helpful feedback from you.) So, it's more like this: y = 0 if x <= 10th percentile of x & z <= 10th percentile of z y = 1 if x <= 10th percentile of x & z > 10th percentile of z y = 2 if x > 10th percentile of x & z <= 10th percentile of z y = 2 if x > 10th percentile of x & z > 10th percentile of z I found that I can do this: centile x z, centile(10) which gives me the 10th percentiles of x and z in the same output. But I don't know how to invoke the result for each variable in my next lines. Truly basic. Thanks again, 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/ * * 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/

**References**:**st: Converting a continuous var into a binary var***From:*Pancho Villa <panchovillainnyc@gmail.com>

**st: RE: Converting a continuous var into a binary var***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: RE: Converting a continuous var into a binary var***From:*Pancho Villa <panchovillainnyc@gmail.com>

**RE: st: RE: Converting a continuous var into a binary var***From:*Howard Lempel <HLempel@brookings.edu>

- Prev by Date:
**RE: st: RE: Converting a continuous var into a binary var** - Next by Date:
**Re: st: RE: Converting a continuous var into a binary var** - Previous by thread:
**RE: st: RE: Converting a continuous var into a binary var** - Next by thread:
**Re: st: RE: Converting a continuous var into a binary var** - Index(es):

© Copyright 1996–2015 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |