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

From |
"Sue Lee" <Sue.Lee@lshtm.ac.uk> |

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

Subject |
st: RE: nested loops for calculating a population 'at risk' |

Date |
Wed, 29 Sep 2004 15:31:13 +0100 |

many thanks for the code below! and apologies for the delay in response. my problem is still this however... how can i get the code below (which generates an 'at risk' number for 1 jan 1988, i.e., the maximum value of sum_atrisk) to generate an 'at risk' number for all the other days from 2 jan 1988 to 31 dec 2000, as well?? is it possible to do this without generating a huge amount of new variables?? the original dataset has approx 100 records of birth for each day and dgest = the days of gestation. gen dgestmin = birthdat - d(1jan1988) + 167 gen dgestmax = dgestmin + 91 gen atrisk = dgest > dgestmin & dgest < dgestmax bysort birthdat: egen atrisk_day = sum(atrisk) by birthdat: gen junk = _n keep if junk==1 gen sum_atrisk = sum(atrisk_day) Sue PhD student London School of Hygiene & Tropical Medicine Sue I'm presuming that what you have is a birthdate (in variable 'date') and gestation at birth in days (variable 'days'). The following (wholly untested) code should then produce a new file containing for each date, the number of women between 168 & 259 days on that date: postfile p date nwomen using newfile.dta forvalues d=`=d(1jan1988)'/`=d(31dec2000)' { count if days-date+`d'>=168 & days-date+`d'<=259 post p (`d') (`r(N)') } postclose p David david@icnarc.org -----Original Message----- From: Sue Lee [mailto:Sue.Lee@lshtm.ac.uk] Sent: 07 September 2004 15:19 To: statalist@hsphsun2.harvard.edu Subject: st: nested loops for calculating a population 'at risk' hello, i'm not exactly new to the list, but i've never posted a question before. i'm really stuck at the moment so i'm hopeful that someone may be able to help... basically, i have a large data set of births from 1 jan 1988 to 31 dec 2000. each birth has its own record. i would like to calculate the number of women at a certain stage of pregnancy on any given day, say between 24 and 37 weeks (which equals 168 to 259 days). so, for example, to calculate the number of women on 1 Jan 1988 who are at this stage of pregnancy, I figure I need to: include all women on that day who are greater than 167 days, but less than 259 days + all women on 2 Jan 1988 who are more than 168 days but less than 260 days + all women on 3 Jan 1988 who are more than 169 days but less than 261 days + all women on 4 Jan 1988 who are more than 170 days but less than 262 days, etc (repeat loop until max value of days is reached) but I can't figure out how to translate this into stata code. One of my big problems is that I have many records for each date (i.e., each baby born on 1 jan 1988 has a record for that day!) and I am stumped on how deal with this in a loop. I hope this makes sense and that someone is feeling generous enough to help me figure this out! Many thanks Best wishes Sue PhD student London School of Hygiene & Tropical Medicine * * 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/

- Prev by Date:
**RE: st: RE: counting** - Next by Date:
**st: xtreg reports a range of obs per group that I don't understand** - Previous by thread:
**Re: st: RE: nested loops for calculating a population 'at risk'** - Next by thread:
**st: overidxt with random effects** - Index(es):

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