Hello!
I have a dataset of medical records where every row of data is a pharmacy dispensation for a certain patient-visit. I would like to create a variable that tells me how many days have occurred between consecutive visits of a patient and a second variable that tells me how many days have elapsed between the patient's first and last visit.
My data is set up as follows: every patient has an ID#, and multiple visit numbers with a specific discharge date.
input str6 animal_number byte visit_num2 str21 dischargedate
"767237" 52 " 3/24/2013"
"767237" 52 " 3/24/2013"
"767237" 52 " 3/24/2013"
"767237" 52 " 3/24/2013"
"767237" 52 " 3/24/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"841194" 20 " 2/3/2017"
"841194" 20 " 2/3/2017"
"841194" 20 " 2/3/2017"
"841194" 20 " 2/3/2017"
"841194" 22 "2/13/2017"
"841194" 28 " 5/9/2017"
"841194" 28 " 5/9/2017"
I've been able to generate the difference between the visit number of the last and first visits by doing this:
bys animal_number: egen last_visit=max(visit_num2)
bys animal_number: egen initial_visit=min(visit_num2)
bys animal_number: gen difference_in_visits=last-initial
but now I would like to be able to do this using the specific dates and also be able to do this with consecutive visits, not just the first and last.
Many thanks for any suggestions!
LR
I have a dataset of medical records where every row of data is a pharmacy dispensation for a certain patient-visit. I would like to create a variable that tells me how many days have occurred between consecutive visits of a patient and a second variable that tells me how many days have elapsed between the patient's first and last visit.
My data is set up as follows: every patient has an ID#, and multiple visit numbers with a specific discharge date.
input str6 animal_number byte visit_num2 str21 dischargedate
"767237" 52 " 3/24/2013"
"767237" 52 " 3/24/2013"
"767237" 52 " 3/24/2013"
"767237" 52 " 3/24/2013"
"767237" 52 " 3/24/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"767237" 54 " 3/31/2013"
"841194" 20 " 2/3/2017"
"841194" 20 " 2/3/2017"
"841194" 20 " 2/3/2017"
"841194" 20 " 2/3/2017"
"841194" 22 "2/13/2017"
"841194" 28 " 5/9/2017"
"841194" 28 " 5/9/2017"
I've been able to generate the difference between the visit number of the last and first visits by doing this:
bys animal_number: egen last_visit=max(visit_num2)
bys animal_number: egen initial_visit=min(visit_num2)
bys animal_number: gen difference_in_visits=last-initial
but now I would like to be able to do this using the specific dates and also be able to do this with consecutive visits, not just the first and last.
Many thanks for any suggestions!
LR
Comment