Hello everyone, I would love some guidance. I have a dataset of ER visits and hospital admissions. I have transposed the data from long to wide. Here is an example below: patient_id encounter_type1 encounter_type2 admtdate1 admtdate2 dschdate1 dschdate2 status1 status2 1 er 1/1/2020 1/1/2020 died 2 er inpatient 3/2/2020 3/6/2020 3/2/2020 5/3/2020 alive died 3 er er 4/4/2020 4/5/202 4/4/2020 4/5/2020 alive died 4 inpatient er 5/2/2020 5/12/2020 5/7/2020 5/12/2020 alive alive encounter_type = ER visit or inpatient (i.e. hospital admission) admtdate = date of admission (inpatient) or service (ER) dschdate = date of discharge status = alive or not I now want to: 1) Create a new variable that sums how many ER visits someone had within the month prior to a hospital admission (if they were admitted); and 2) Create a new variable that specifies where a person died (ER or inpatient) I am imagining the output looking something like this: patient_id encounter_type1 encounter_type2 admtdate1 admtdate2 dschdate1 dschdate2 status1 status2 newvar1 newvar2 1 er 1/1/2020 1/1/2020 died . er 2 er inpatient 3/2/2020 3/6/2020 3/2/2020 5/3/2020 alive died 1 inpatient 3 er er 4/4/2020 4/5/202 4/4/2020 4/5/2020 alive died . er 4 inpatient er 5/2/2020 5/12/2020 5/7/2020 5/12/2020 alive alive 0 I thank you in advance for your time and expertise.
... View more