Hello. I have a simplified data set (see below) with variables subject_id, encounter_date and encounter_num. I am interested in counting repeat encounters that happen >1 but <15 days after the first encounter. In addition, I would like to carry out the same process for subsequent encounters, as long as they were >30 days from the prior index encounter. For the subject 33204 listed below, I would like to be able to use encounter number 1 as the initial event, then count encounters 4 and 5 (because they occurred >1 and <15 days from encounter 1.) Then I would like to next identify and use encounter number 8 (because it occurred 30 days from the prior index encounter) and count encounter 9 (occurred >1 and <15 days from encounter 8). Essentially I'm trying to count the number of events that occur in a specific time period and repeat this process every 30 days.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double subject_id float(encounter_date encounter_num) 33204 18265 1 33204 18265 2 33204 18265 3 33204 18269 4 33204 18275 5 33204 18288 6 33204 18288 7 33204 18302 8 33204 18311 9 33204 18324 10 33204 18337 11 33204 18393 12 33204 18394 13 33204 18419 14 33204 18420 15 33204 18428 16 33204 18456 17 33204 18526 18 33204 18530 19 33204 18532 20 33204 18541 21 33204 18570 22 33204 18599 23 33204 18632 24 33204 18655 25 33204 18686 26 33205 18265 1 33205 18266 2 33205 18272 3 33205 18293 4 33205 18331 5 33205 18348 6 33205 18393 7 33205 18444 8 33205 18543 9 33205 18637 10 33205 18687 11 33205 18693 12 33205 18694 13 33205 18725 14 33205 18892 15 33205 19005 16 end format %td encounter_date
Comment