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

From |
Christian Weiß <mail@cweiss.org> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: Testing for a particular value and replacing in last observation? |

Date |
Fri, 11 Sep 2009 17:59:56 -0400 |

Exactly! Cheers! Chris On Fri, Sep 11, 2009 at 5:47 PM, Kieran McCaul <Kieran.McCaul@uwa.edu.au> wrote: > ... > > Is this what you mean? > > clear > > set obs 10 > > gen x = uniform()*10 > > set obs `=_N+1' > > summ x, meanonly > local max = r(max) > replace x=1 if `max'<2 in l > replace x=2 if `max'>=2 & `max'<5 in l > replace x=3 if `max'>=5 & `max'<. in l > > > > > > ______________________________________________ > Kieran McCaul MPH PhD > WA Centre for Health & Ageing (M573) > University of Western Australia > Level 6, Ainslie House > 48 Murray St > Perth 6000 > Phone: (08) 9224-2701 > Fax: (08) 9224 8009 > email: Kieran.McCaul@uwa.edu.au > http://myprofile.cos.com/mccaul > http://www.researcherid.com/rid/B-8751-2008 > ______________________________________________ > If you live to be one hundred, you've got it made. > Very few people die past that age - George Burns > > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Christian Weiß > Sent: Saturday, 12 September 2009 2:33 AM > To: statalist > Subject: st: Testing for a particular value and replacing in last observation? > > Dear Statalist, > > assume there is one variable x with 10 observations filled with > random numbers between 0 and 10. > the 11th observation should carry the value 1 if ANY observation of x > is <2, 2 if any observation is between 2 and 5, and 3 if any > observation is bigger than 5. > > I tried the following: > > local obs = 10 > local count = 0 > > while `count' <= `obs' { > > replace x = 1 if x < 2 in `count' > replace x = 2 if ....and so so on > > } > > apparently, this does not work as intended, as this loop does not > place the values 1, 2, 3 in the last observation but in the > observation `count' > I actually need an additional "in" > replace x = 1 in L if x < 2 in `count' > > Unfortunately, stata does not allow for this systanx > > Do you have any hint for a workaround? > > Best, > Christian > * > * 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: Testing for a particular value and replacing in last observation?***From:*Christian Weiß <mail@cweiss.org>

**st: RE: Testing for a particular value and replacing in last observation?***From:*"Kieran McCaul" <Kieran.McCaul@uwa.edu.au>

- Prev by Date:
**st: AW: Table command limited to 5 Statistics?** - Next by Date:
**AW: Rép. : st: RE: Export results after -tabdisp-** - Previous by thread:
**st: RE: Testing for a particular value and replacing in last observation?** - Next by thread:
**st: Reset test** - Index(es):

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