[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Sebastian F. Büchte" <sfbuechte@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: programming problem |

Date |
Thu, 16 Aug 2007 20:03:13 +0200 |

I have got a -reshape- solution of which I do not really think that it qualifies for "elegant". Here it is: //unless you have an admission id you need to create one... gen admid = _n reshape long v, i(admid) j(admmo) gen mycond = v == 1 & month == admmo bys admid (mycond): replace mycond = mycond[_N] reshape wide v, i(admid) j(admmo) Regards Sebastian On 8/16/07, Nick Cox <n.j.cox@durham.ac.uk> wrote: > Short of a solution using -reshape-, I think > this will suit: > > gen mycond = 0 > forval j = 1/12 { > replace mycond = 1 if `j' == month & var`j' == 1 > } > > where I assume that your -var*- are 1 when true. > > Nick > n.j.cox@durham.ac.uk > > Jeph Herrin > > > I have observations on patient admissions over > > a 12 month period. > > > > For each observation, I have 12 variables, call > > them var1-var12, which indicate whether a certain > > condition was met for that patient for months 1-12. > > So, eg, it may be true for months 1-3 and 7-12. > > > > I also have a variable -month-, which indicates > > the current month of the observed admission. What > > I want to capture is whether the condition was true > > in the month of admission. > > > > For instance, at first I unthinkingly tried this: > > > > gen mycond = var`=month'==1 > > > > but this of course uses the first observed value > > of -month-, which happens to be 6, and only checks > > -var6-. > > > > I eventually got there by creating lots of vars, but is > > there a more direct solution? > > > > * > * For searches and help try: > * http://www.stata.com/support/faqs/res/findit.html > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: programming problem***From:*Jeph Herrin <junk@spandrel.net>

**st: RE: programming problem***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: Non-Linear Least Squares Programming Question** - Next by Date:
**Re: st: RE: programming problem** - Previous by thread:
**st: RE: programming problem** - Next by thread:
**Re: st: RE: programming problem** - Index(es):

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