Dear Statalist
I am trying to run a cox regression model to look at hazard for admission to hospital within 28 days of a positive test for an infection. Please can I ask about how to incorporate time varying predictors in to this model, and if I have done this correctly?
The exposure I am interested in is vaccination status. Participants may be vaccinated at the start of the follow-up period, or get vaccinated during the follow-up period, so I need to account for this in the model as a time varying predictor
The follow-up period starts on the day of the positive test, and ends 28 days later. During the 28 days either the outcome of interest can occur (they are admitted) or they get vaccinated.
The data are long, I have included a mock up of the data below
Data point is either the start of the follow-up period when the positive test occurred, the date when a vacine was received, the date when the outcome occurred, or the date when the follow-up period ends.
Time is the number of days from the positive test to each data point
Outcome of interest is coded 1 if the participant is admitted
Exposed is coded 1 if the participant is exposed at each data point
so
participant 1 is unvaccinated when they test positive, gets vaccinated 4 days later, and then doesnt get admitted during the rest of the follow-up time
participant 2 is unvaccinated when they test positive, and doesnt get admitted during the rest of the follow up time
participant 3 is vaccinated when they test positive, and gets admitted 13 days later
To analyse this
I first run
st set time, id(id) failure(outcome_of_interest)
and then run
stcox exposed
And I think this then gives the hazard ratio of admission between exposed vs unexposed participants. Is anyone able to tell me if I'm doing this correctly? Specifically, do I need to add a time observation for each day between each datapoint, or is how I've done it OK?
Any help would be great - thank you!
Best Wishes
Joe
I am trying to run a cox regression model to look at hazard for admission to hospital within 28 days of a positive test for an infection. Please can I ask about how to incorporate time varying predictors in to this model, and if I have done this correctly?
The exposure I am interested in is vaccination status. Participants may be vaccinated at the start of the follow-up period, or get vaccinated during the follow-up period, so I need to account for this in the model as a time varying predictor
The follow-up period starts on the day of the positive test, and ends 28 days later. During the 28 days either the outcome of interest can occur (they are admitted) or they get vaccinated.
The data are long, I have included a mock up of the data below
Data point is either the start of the follow-up period when the positive test occurred, the date when a vacine was received, the date when the outcome occurred, or the date when the follow-up period ends.
Time is the number of days from the positive test to each data point
Outcome of interest is coded 1 if the participant is admitted
Exposed is coded 1 if the participant is exposed at each data point
| id | Data point | Outcome_of_interest | Exposed | Time |
| 1 | Positive test | 0 | 0 | 0 |
| 1 | Vaccine received | 0 | 1 | 4 |
| 1 | End of follow up | 0 | 1 | 28 |
| 2 | Positive test | 0 | 0 | 0 |
| 2 | End of follow up | 0 | 0 | 28 |
| 3 | Positive test | 0 | 1 | 0 |
| 3 | Admitted | 1 | 1 | 13 |
participant 1 is unvaccinated when they test positive, gets vaccinated 4 days later, and then doesnt get admitted during the rest of the follow-up time
participant 2 is unvaccinated when they test positive, and doesnt get admitted during the rest of the follow up time
participant 3 is vaccinated when they test positive, and gets admitted 13 days later
To analyse this
I first run
st set time, id(id) failure(outcome_of_interest)
and then run
stcox exposed
And I think this then gives the hazard ratio of admission between exposed vs unexposed participants. Is anyone able to tell me if I'm doing this correctly? Specifically, do I need to add a time observation for each day between each datapoint, or is how I've done it OK?
Any help would be great - thank you!
Best Wishes
Joe

Comment