Dear All,
I have a dataset of 45,000,000 observations each of which is a hospital admission. Many of these admission episodes belong to the same individual, who is identified by the variable named token_person_id. Some of these admission episodes will contain an operative intervention of interest which is identified by a variable named opnum (opnum != .) The date of this operative intervention of interest will be stored in a variable named opdate which is filled only for the episode in which the operation happened.
I would like to:
1) Identify all episodes for all individuals who have an episode with one of these operative interventions of interest, and drop all episodes from individuals who have never had one
2) Be able to collate values across admissions for an individual (i.e. if in one admission there is a diagnosis of neurological disease and in another there is a diagnosis of kidney disease, i wish to be able to see in one row that there has been both neurological and kidney disease)
3) Perform 2 with respect to a timeframe between opdate and admission date (admidate) (i.e. identify whether there was a diagnosis of neurological disease in any episodes in the five years before the operation)
Example data
I would appreciate any help or advice,
Thank you!
I have a dataset of 45,000,000 observations each of which is a hospital admission. Many of these admission episodes belong to the same individual, who is identified by the variable named token_person_id. Some of these admission episodes will contain an operative intervention of interest which is identified by a variable named opnum (opnum != .) The date of this operative intervention of interest will be stored in a variable named opdate which is filled only for the episode in which the operation happened.
I would like to:
1) Identify all episodes for all individuals who have an episode with one of these operative interventions of interest, and drop all episodes from individuals who have never had one
2) Be able to collate values across admissions for an individual (i.e. if in one admission there is a diagnosis of neurological disease and in another there is a diagnosis of kidney disease, i wish to be able to see in one row that there has been both neurological and kidney disease)
3) Perform 2 with respect to a timeframe between opdate and admission date (admidate) (i.e. identify whether there was a diagnosis of neurological disease in any episodes in the five years before the operation)
Example data
| token_person_id | opnum | opdate | admidate | neuro | ckd |
| 1 | . | . | 05nov2017 | 1 | 0 |
| 1 | 1 | 23jul2018 | 23jul2018 | 0 | 0 |
| 1 | . | . | 05jan2012 | 0 | 1 |
| 2 | 1 | 01dec2014 | 01dec2014 | 1 | 0 |
| 2 | . | . | 12mar2012 | 1 | 0 |
| 2 | . | . | 10may2016 | 0 | 1 |
| 3 | . | . | 05dec2022 | 0 | 0 |
| 3 | . | . | 03jan2010 | 0 | 0 |
| 3 | . | . | 04apr2018 | 0 | 0 |
Thank you!

Comment