Hi There - I have patient-level data on events of care for different conditions. The data are structured as below (example for a single patient):
I would like to create a new variable including the date when an event related to condition ID "2" has occurred after the observation event date. The output I am looking to replicate would look like the fourth column of the table below - for each observation, the fourth column includes the date when the next event related to condition "2" has occurred.
Any advice on how this variable may be created? The difficulty here seems that the information to extract from the Event Date column is always in a different position. Also, I would indeed need to create the variable for each patient in the data so I suspect a "by Patient" command is needed?
Many thanks in advance!
| Patient Id | Cond Id | Event Date |
| 1 | 1 | 01/01/2010 |
| 1 | 1 | 01/05/2013 |
| 1 | 2 | 01/07/2014 |
| 1 | 3 | 01/12/2016 |
| 1 | 1 | 01/01/2017 |
| 1 | 2 | 01/04/2017 |
| 1 | 2 | 01/01/2018 |
| 1 | 3 | 01/10/2018 |
| 1 | 3 | 01/10/2019 |
| 1 | 2 | 01/09/2020 |
| Patient Id | Cond Id | Event Date | Cond 2 Event Date |
| 1 | 1 | 01/01/2010 | 01/07/2014 |
| 1 | 1 | 01/05/2013 | 01/07/2014 |
| 1 | 2 | 01/07/2014 | 01/04/2017 |
| 1 | 3 | 01/12/2016 | 01/04/2017 |
| 1 | 1 | 01/01/2017 | 01/04/2017 |
| 1 | 2 | 01/04/2017 | 01/01/2018 |
| 1 | 2 | 01/01/2018 | 01/09/2020 |
| 1 | 3 | 01/10/2018 | 01/09/2020 |
| 1 | 3 | 01/10/2019 | 01/09/2020 |
| 1 | 2 | 01/09/2020 | . |
Many thanks in advance!

Comment