Dear prof.Schechter,
I tried your code , in which that you have assumed that each drug is consumed at a rate of 1 per day in my real data. But there is some problem with my real data; there medications are coded by ATC5 code and some of the medications are combined in a single dosage forms and coded under one ATC5 code. I am having issue with these combinations of medications. I tried the below code from STATA forum which gives name of medication regimens. But in real data it does not work well (it takes more than 24 hours for one extract) and seems still can not deal with combination of medications which coded under one ATC5 code.
I would really appreciate if you may help me solve the problem.
Thank you
clear
input byte ID str9 startdate str9 lastdate str7 drug
2 "24-Aug-95" "14-Nov-97" "A01AD05"
2 "14-Nov-97" "15-Jun-00" "B01AC04"
3 "14-Nov-97" "13-Feb-03" "C10AA05"
3 "15-Jun-00" "13-Feb-03" "B01AC04"
3 "15-Jun-00" "13-Feb-03" "A01AD05"
end
generate int calendar_dt1 = date(startdate, "DMY", 2020)
generate int calendar_dt0 = date(lastdate, "DMY", 2020)
generate long row_nr = _n
quietly reshape long calendar_dt, i(row_nr) j(action)
label define Actions 1 Add 0 Remove
label values action Actions
drop startdate lastdate row_nr
format calendar_dt %tdCCYY-NN-DD
egen long event_nr = group(calendar_dt)
gsort +event_nr -action
order ID event_nr action drug calendar_dt
list, noobs sepby(event_nr) abbreviate(20)
generate str drug_regimen = drug if action == "Add":Actions
replace drug_regimen = trim(itrim(cond(action == "Add":Actions, drug_regimen + " " + drug_regimen[_n-1], subinword(drug_regimen[_n-1], drug, "", 1)))) if _n > 1
list, noobs sepby(event_nr) abbreviate(20)
by event_nr: keep if _n == _N
generate byte drug_tally = wordcount(drug_regimen)
list ID event_nr calendar_dt drug_regimen drug_tally, noobs abbreviate(20)
I tried your code , in which that you have assumed that each drug is consumed at a rate of 1 per day in my real data. But there is some problem with my real data; there medications are coded by ATC5 code and some of the medications are combined in a single dosage forms and coded under one ATC5 code. I am having issue with these combinations of medications. I tried the below code from STATA forum which gives name of medication regimens. But in real data it does not work well (it takes more than 24 hours for one extract) and seems still can not deal with combination of medications which coded under one ATC5 code.
I would really appreciate if you may help me solve the problem.
Thank you
clear
input byte ID str9 startdate str9 lastdate str7 drug
2 "24-Aug-95" "14-Nov-97" "A01AD05"
2 "14-Nov-97" "15-Jun-00" "B01AC04"
3 "14-Nov-97" "13-Feb-03" "C10AA05"
3 "15-Jun-00" "13-Feb-03" "B01AC04"
3 "15-Jun-00" "13-Feb-03" "A01AD05"
end
generate int calendar_dt1 = date(startdate, "DMY", 2020)
generate int calendar_dt0 = date(lastdate, "DMY", 2020)
generate long row_nr = _n
quietly reshape long calendar_dt, i(row_nr) j(action)
label define Actions 1 Add 0 Remove
label values action Actions
drop startdate lastdate row_nr
format calendar_dt %tdCCYY-NN-DD
egen long event_nr = group(calendar_dt)
gsort +event_nr -action
order ID event_nr action drug calendar_dt
list, noobs sepby(event_nr) abbreviate(20)
generate str drug_regimen = drug if action == "Add":Actions
replace drug_regimen = trim(itrim(cond(action == "Add":Actions, drug_regimen + " " + drug_regimen[_n-1], subinword(drug_regimen[_n-1], drug, "", 1)))) if _n > 1
list, noobs sepby(event_nr) abbreviate(20)
by event_nr: keep if _n == _N
generate byte drug_tally = wordcount(drug_regimen)
list ID event_nr calendar_dt drug_regimen drug_tally, noobs abbreviate(20)
Comment