- [INDENT=4] Dear all,
Currently I am trying to count the number of each-drug (anti-thrombotic and lipid lowering agents) days in a year. I have some commands for calculation for single agent but I'm working on big dataset thus it seems it will take a lot of time if I use these commands.
I would really appreciate if anyone may help me to create loops for this calculation.
clear
input id aspirin2006 clopidogrel2006 statin2006 fibrate2006 aspirin2007 clopidogrel2007 statin2007 fibrate2007 aspirin2008 clopidogrel2008 statin2008 fibrate2008 aspirin2009 clopidogrel2009 statin2009 fibrate2009 aspirin2010 clopidogrel2010 statin2010 fibrate2010 sex date_of_DS date_of_MI date_of_death index_date last_date
1 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 1 1 0 1 2007 . . 2007 2010
2 0 0 1 0 1 0 0 1 0 0 0 0 0 1 0 1 1 0 0 1 2 2005 . . 2006 2010
3 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 2007 . . 2007 2009
4 0 0 1 0 0 1 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 1999 2009 2009 2006 2009
5 0 0 0 1 0 0 0 1 0 0 0 1 0 1 1 1 1 1 1 1 2 2000 . . 2007 2009
6 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 0 1 2 1998 2010 . 2006 2010
7 0 0 0 1 0 0 0 1 1 0 0 1 0 0 1 0 0 1 0 0 1 2001 . . 2006 2009
8 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 1 2002 . . 2007 2010
9 0 0 0 0 0 1 0 1 0 1 0 1 0 1 1 1 1 0 0 0 2 1996 2008 2008 2006 2008
end
Commands (only for 1-drug):
*Calculate cumulative days, based on index_date and qty
sort id supp_date
bysort id: gen pat_index = _n
gen date_covered = index_date
format date_covered %td
replace date_covered = date_covered[_n-1] + qty[_n-1] if pat_index>1 & pat_id==pat_id[_n-1]
gen supply_gap = supp_date - date_covered
*Censored date
gen last_follow_date = mdy(12, 31, 2010)
format last_follow_date %td
*6-month assessment
sort id pat_index
gen date_6mth = index_date+ 183
format date_6mth %td
replace date_6mth = date_of_death if date_of_death<date_6mth
gen valid_6mth = .
replace valid_6mth = 1 if supp_date<(index_date+ 183) & date_of_death>(index_date+183)
gen patid_6mth = pat_id if valid_6mth==1
sort id pat_index
gen gap_6mth = .
replace gap_6mth = supply_gap-supply_gap[_n-1] if supply_gap>0 & valid_6mth==1 & supply_gap>supply_gap[_n-1]
replace gap_6mth = supply_gap-0 if supply_gap>0 & valid_6mth==1 & supply_gap>supply_gap[_n-1] & supply_gap[_n-1]<0
bysort patid_6mth: egen days_6mth = sum(gap_6mth)
replace days_6mth = . if patid_6mth==.
bysort patid_6mth: egen qty_6mth = sum(qty)
replace qty_6mth = . if patid_6mth==.
gen overall_gap_6mth = 183-qty_6mth
replace days_6mth = overall_gap_6mth if overall_gap_6mth>days_6mth
gen pdc_6mth = .
replace ndc_6mth = (183-days_6mth)/183
replace ndc_6mth = 0 if pdc<0
gen pdc_6mth_80 =.
replace pdc_6mth_80 =1 if pdc_6mth<=0.79
replace pdc_6mth_80 =2 if pdc_6mth>=0.20 & pdc_6mth>=0.80
Thank you so much.
Oyun
- Quote
- Flag
- Like 0
[/INDENT]
-
Login or Register
- Log in with
Comment