Hello,
I have a number of variables. [ id (group id), med (medication), date (date medication taken), start ( beginning of observation period), end (end of observation period) ]
I want to generate a variable called treated that:
* coded as 1
- if the patient received medication1 or medication 3
- and the date (date variable) of 3 consecutive prescriptions (either for med 1 or med 3) is within 180 days period
- and the 180 days period must be within the observational period ( after start and before end)
* coded as 0 otherwise
The problem is that I am using a huge panel data and the medications received could be over a period of years and I need only to group the patients who received a continuous treatment (180 days) of medication 1 or medication 3 only. The gap between the received medication can sometimes be more than 180 days and the patient could start a continuous treatment period before completing 180 days in a previous continuous treatment trial. Also sometimes the continuous treatment period is outside the observational period.
Some patients could have more than one continuous treatment period within the observational period. If possible I need also to count the number of those periods per id.
Please find below an artificial sample of my data:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float id str4 med double(date start end)
1 "med2" 19002 18871 19539
1 "med3" 19002 18871 19539
1 "med2" 19025 18871 19539
1 "med3" 19067 18871 19539
1 "med3" 19094 18871 19539
1 "med1" 19188 18871 19539
1 "med2" 19218 18871 19539
1 "med1" 19218 18871 19539
1 "med1" 19276 18871 19539
1 "med2" 19449 18871 19539
2 "med2" 20210 19967 20635
2 "med1" 20273 19967 20635
2 "med3" 20367 19967 20635
2 "med1" 20430 19967 20635
3 "med3" 20031 19602 20269
3 "med3" 20075 19602 20269
3 "med3" 20120 19602 20269
3 "med2" 20157 19602 20269
3 "med2" 20218 19602 20269
3 "med1" 20370 19602 20269
end
format %td date
format %td start
format %td end
Thank you
I have a number of variables. [ id (group id), med (medication), date (date medication taken), start ( beginning of observation period), end (end of observation period) ]
I want to generate a variable called treated that:
* coded as 1
- if the patient received medication1 or medication 3
- and the date (date variable) of 3 consecutive prescriptions (either for med 1 or med 3) is within 180 days period
- and the 180 days period must be within the observational period ( after start and before end)
* coded as 0 otherwise
The problem is that I am using a huge panel data and the medications received could be over a period of years and I need only to group the patients who received a continuous treatment (180 days) of medication 1 or medication 3 only. The gap between the received medication can sometimes be more than 180 days and the patient could start a continuous treatment period before completing 180 days in a previous continuous treatment trial. Also sometimes the continuous treatment period is outside the observational period.
Some patients could have more than one continuous treatment period within the observational period. If possible I need also to count the number of those periods per id.
Please find below an artificial sample of my data:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float id str4 med double(date start end)
1 "med2" 19002 18871 19539
1 "med3" 19002 18871 19539
1 "med2" 19025 18871 19539
1 "med3" 19067 18871 19539
1 "med3" 19094 18871 19539
1 "med1" 19188 18871 19539
1 "med2" 19218 18871 19539
1 "med1" 19218 18871 19539
1 "med1" 19276 18871 19539
1 "med2" 19449 18871 19539
2 "med2" 20210 19967 20635
2 "med1" 20273 19967 20635
2 "med3" 20367 19967 20635
2 "med1" 20430 19967 20635
3 "med3" 20031 19602 20269
3 "med3" 20075 19602 20269
3 "med3" 20120 19602 20269
3 "med2" 20157 19602 20269
3 "med2" 20218 19602 20269
3 "med1" 20370 19602 20269
end
format %td date
format %td start
format %td end
Thank you
Comment