Statalist The Stata Listserver


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

st: programming puzzle


From   Jeph Herrin <junk@spandrel.net>
To   statalist@hsphsun2.harvard.edu
Subject   st: programming puzzle
Date   Sun, 15 Oct 2006 12:25:09 -0400

Listers,

I'm hoping for some insight into a solution to the following
programming problem.

For 170k patients (ID), I have the dates they filled prescriptions
(-filldate-) and the number of -days- each prescription covers (eg,
the number of daily pills):

ID    filldate  days
1      10JAN01   30
1      20FEB01   14
1      03MAR01   45
1      05MAY01   30
.
.
2       etc
2
2
.
.
.

The problem is that I need to figure how many total -days- they
are covered out of each 90 day quarter. So in the above, the first
patient starts on 10JAN01, so the first 90 day quarter ends on
10APR01. That means I need to break the 3rd record (03MAR01) into
two records, 38 days for the first quarter and 7 days for the second
quarter. I have to do this for all four 90 day quarters starting
10JAN01, and I have to do for every patient (and they all have
different start dates).

What I'd like to do is insert a new record at the start of each
quarter UNLESS they already have a record for that date. Then
the last -filldate- for each quarter would be split to form the
new record.

However, all of my attempts end up looking hopelessly complex
and hence unreliable, and as I so often discover elegant solutions
on this list I thought I'd fish for one here. Any ideas would
be welcome.

cheers,
Jeph
--
Jeph Herrin
jeph.herrin@yale.edu



*
*   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/



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