[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: nested loops for calculating a population 'at risk'
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
+ all women on 3 Jan 1988 who are more than 169 days but less than 261
+ all women on 4 Jan 1988 who are more than 170 days but less than 262
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!
London School of Hygiene & Tropical Medicine
* For searches and help try: