Hi,
Sorry for this basic programming question, but I would appreciate any help with it.
I have a dataset of inpatient discharges with several visits per patient and procedures. this means several rows per visit and per patient. I need to create a readmission variable after certain procedures e.g. PCI). Below there is a simplified example of the dataset . Only one patient, but with 3 visits. dentry (date of admission) dexit (date of discharge) PCI-dummy of whether the procedure was performed in that visit. pid -patient id case_id -visit or event id.
I will eventually rid off the extra rows, but I want to compute the variables as it is if possible first. I create a variable for visit, and number of visits
sort dentry
by case_id, sort: gen visit = _n == 1
egen visits=sum(visit), by(pid)
and I tried the following command, for general readmission
bysort pid (visit): gen readmit_interval = ((dentry-dexit[_n-1]))
I got negative values, so I am guessing I need a variable that order the visits,
but my main question is how to create the same readmission variable using the procedure visit as index. Right now the variable uses the first visit chronologically as index ?
Many thanks in advance for your time and suggestions!
Sorry for this basic programming question, but I would appreciate any help with it.
I have a dataset of inpatient discharges with several visits per patient and procedures. this means several rows per visit and per patient. I need to create a readmission variable after certain procedures e.g. PCI). Below there is a simplified example of the dataset . Only one patient, but with 3 visits. dentry (date of admission) dexit (date of discharge) PCI-dummy of whether the procedure was performed in that visit. pid -patient id case_id -visit or event id.
pid | case_id | visit | nvisits | dentry | dexit | PCI |
XXXXXX | 100 | 1 | 3 | 19563 | 19565 | 0 |
XXXXXX | 100 | 0 | 3 | 19563 | 19565 | 0 |
XXXXXX | 100 | 0 | 3 | 19445 | 19453 | 0 |
XXXXXX | 100 | 0 | 3 | 19445 | 19453 | 0 |
XXXXXX | 100 | 0 | 3 | 19445 | 19453 | 0 |
XXXXXX | 152 | 1 | 3 | 19871 | 19876 | 1 |
XXXXXX | 152 | 0 | 3 | 19871 | 19876 | 1 |
XXXXXX | 152 | 0 | 3 | 19871 | 19876 | 1 |
XXXXXX | 152 | 0 | 3 | 19871 | 19876 | 1 |
XXXXXX | 152 | 0 | 3 | 19871 | 19876 | 1 |
XXXXXX | 152 | 0 | 3 | 19871 | 19876 | 1 |
XXXXXX | 152 | 0 | 3 | 19871 | 19876 | 1 |
XXXXXX | 180 | 1 | 3 | 20004 | 20008 | 0 |
XXXXXX | 180 | 0 | 3 | 20004 | 20008 | 0 |
XXXXXX | 180 | 0 | 3 | 20004 | 20008 | 0 |
XXXXXX | 180 | 0 | 3 | 20004 | 20008 | 0 |
XXXXXX | 180 | 0 | 3 | 20004 | 20008 | 0 |
I will eventually rid off the extra rows, but I want to compute the variables as it is if possible first. I create a variable for visit, and number of visits
sort dentry
by case_id, sort: gen visit = _n == 1
egen visits=sum(visit), by(pid)
and I tried the following command, for general readmission
bysort pid (visit): gen readmit_interval = ((dentry-dexit[_n-1]))
I got negative values, so I am guessing I need a variable that order the visits,
but my main question is how to create the same readmission variable using the procedure visit as index. Right now the variable uses the first visit chronologically as index ?
Many thanks in advance for your time and suggestions!