Hi,
I am working with an emergency department dataset with 12 years of data. I would like to identify patients that have 5 or more emergency department visits in 12-month rolling intervals. To do this I am using rangestat in Stata 17 as follows:
bysort patient_id: gen total_count = _n
rangestat (count) rolling_count = total_count, interval(arrival_date -364 0) by(patient_id)
I would like to flag patients with runs of 5 or more visits in rolling 12-month intervals. For example, for patient 6 I would like the run of 5 or more visits to be flagged as 1 and for patient 6 where the run is <5 to be 0 as seen in wanted.
I have a feeling I may need to use rangerun as follows:
rangerun total_count, interval(arrival_date -364 0) by(patient_id)
However, I am uncertain of how to define/construct a program with the commands.
There have been a number of threads if have reviewed as suggested such as https://www.statalist.org/forums/for...evious-5-years, but am still unable to follow (I am very new to coding).
Thank you, Mary
I am working with an emergency department dataset with 12 years of data. I would like to identify patients that have 5 or more emergency department visits in 12-month rolling intervals. To do this I am using rangestat in Stata 17 as follows:
bysort patient_id: gen total_count = _n
rangestat (count) rolling_count = total_count, interval(arrival_date -364 0) by(patient_id)
I would like to flag patients with runs of 5 or more visits in rolling 12-month intervals. For example, for patient 6 I would like the run of 5 or more visits to be flagged as 1 and for patient 6 where the run is <5 to be 0 as seen in wanted.
I have a feeling I may need to use rangerun as follows:
rangerun total_count, interval(arrival_date -364 0) by(patient_id)
However, I am uncertain of how to define/construct a program with the commands.
There have been a number of threads if have reviewed as suggested such as https://www.statalist.org/forums/for...evious-5-years, but am still unable to follow (I am very new to coding).
Thank you, Mary
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int patient_id float(arrival_date total_count) double rolling_count float wanted 1 17958 1 1 0 1 18223 2 2 0 1 18527 3 2 0 1 19075 4 1 0 1 19757 5 1 0 1 20737 6 1 0 1 20743 7 2 0 2 18031 1 1 0 2 19416 2 1 0 2 19676 3 2 0 3 17955 1 1 0 4 21813 1 1 0 5 18089 1 1 0 5 19535 2 1 0 5 20826 3 1 0 6 18368 1 1 1 6 18385 2 2 1 6 18406 3 3 1 6 18430 4 4 1 6 18494 5 5 1 6 18552 6 6 1 6 18558 7 7 1 6 18563 8 8 1 6 20429 9 1 0 6 20891 10 1 0 6 21605 11 1 0 6 23006 12 1 0 7 20869 1 1 0 7 22486 2 1 0 8 18631 1 1 0 8 18632 2 2 0 8 19548 3 1 0 8 19549 4 2 0 8 20689 5 1 0 8 20990 6 2 0 9 18413 1 1 0 9 19453 2 1 0 9 19469 3 2 0 9 20059 4 1 0 9 20195 5 2 0 9 20354 6 3 0 9 20739 7 1 0 9 20754 8 2 0 9 20825 9 3 0 9 20843 10 4 0 10 21158 1 1 0 10 21184 2 2 0 10 21205 3 3 0 10 21656 4 1 1 10 21858 5 2 1 10 21910 6 3 1 10 21946 7 4 1 10 21976 8 5 1 end format %td arrival_date

Comment