Statalist The Stata Listserver

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

Re: st: programming puzzle

From   Jeph Herrin <>
Subject   Re: st: programming puzzle
Date   Sun, 15 Oct 2006 12:47:11 -0400

I should clarify that the -days- typically fall short or
overlap the subsequent -filldate-, and that not all patients
have -filldates- for the entire 360 days.

Jeph Herrin wrote:

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

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.

Jeph Herrin

*   For searches and help try:

*   For searches and help try:

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