I'm currently coding up an algorithm that deals with prescription drug refills.
The theory behind the code/loop I'm struggling with is that since patients refill their medications earlier than the day they run out of medicine (we know how many days worth of medication they were supplied with), to capture how compliant they are with a medication you have to adjust the start/end dates of the fill to accommodate for overlap.
The dataset is quite large but is taking an extensively long time (days) to make it through the code. I was hoping someone could offer feedback as to whether my code for the loop is super inefficient or it's just a byproduct of having a large dataset.
The theory behind the code/loop I'm struggling with is that since patients refill their medications earlier than the day they run out of medicine (we know how many days worth of medication they were supplied with), to capture how compliant they are with a medication you have to adjust the start/end dates of the fill to accommodate for overlap.
The dataset is quite large but is taking an extensively long time (days) to make it through the code. I was hoping someone could offer feedback as to whether my code for the loop is super inefficient or it's just a byproduct of having a large dataset.
Code:
local GROUPVAR drug_class * Adjust dates to account for overlap (i.e. early fills) local keepgoing = 1 while `keepgoing' != 0 { sort PATID `GROUPVAR' FILL_DT qui by PATID `GROUPVAR': replace FILL_DT = (END_DT[_n-1] + 1) if (END_DT[_n-1] > FILL_DT[_n]) & _n != 1 * We need to know whether to keep looping qui count if END_DT != FILL_DT + DAYS_SUP if (r(N) > 0) { local keepgoing = 1 } if (r(N) == 0) { local keepgoing = 0 } qui replace END_DT = FILL_DT + DAYS_SUP }
Comment