Hello,
I have a dataset with multiple observations per person. There can be multiple incidences in a given year for up to 5 years. I want to create a binary variable that will update in a current year based on a previous year (different row) by unique identifier. The data is in long format. So far I've been able create dummy variables within each year for the injury of interest and a cumulative variable across all years but these don't address my issue.
Essentially I need a binary medical history variable.
I have a dataset with multiple observations per person. There can be multiple incidences in a given year for up to 5 years. I want to create a binary variable that will update in a current year based on a previous year (different row) by unique identifier. The data is in long format. So far I've been able create dummy variables within each year for the injury of interest and a cumulative variable across all years but these don't address my issue.
Essentially I need a binary medical history variable.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float newid int school_year_key float(concussion17 concussion18 concussion19 concussion20 any_concussion) 4 2018 0 0 0 0 0 5 2018 0 0 0 0 0 6 2019 0 0 0 0 0 6 2020 0 0 0 0 0 7 2019 0 0 0 0 0 8 2018 0 1 0 0 2 8 2017 0 0 0 0 2 8 2019 0 0 1 0 2 9 2017 0 0 0 0 1 9 2020 0 0 0 0 1 9 2019 0 0 0 0 1 9 2017 0 0 0 0 1 9 2018 0 0 0 0 1 9 2019 0 0 0 0 1 9 2017 1 0 0 0 1 9 2020 0 0 0 0 1 10 2018 0 0 0 0 0 10 2017 0 0 0 0 0 10 2018 0 0 0 0 0 10 2019 0 0 0 0 0 end
Comment