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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

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

Subject |
st: RE: programming problem |

Date |
Thu, 16 Aug 2007 18:53:30 +0100 |

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/

**Follow-Ups**:**Re: st: RE: programming problem***From:*"Sebastian F. Büchte" <sfbuechte@gmail.com>

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

- Prev by Date:
**st: programming problem** - Next by Date:
**st: RE: Non-Linear Least Squares Programming Question** - Previous by thread:
**st: 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 |