One of the cohort studies I have carried out recently involved examining the association between post-diagnostic beta-blocker use and breast cancer outcomes in a cohort of breast cancer patients. Briefly, I followed patients up from their breast cancer diagnosis until death or end of 2017, and treated beta-blocker use as a time-varying covariate. That is, people were considered nonusers of beta blockers until their first post-diagnostic beta blocker dispensing, and once they were a user they were a user until the end of follow-up. For people who used beta blockers, they have two rows of data in my STATA dataset, with the rows split based on when they first used the beta blocker. An example of this data is shown below:
In this dataset, 'time5' represents each patient's entire follow-up time, and 'timetofbetablocker' is the time between breast cancer diagnosis and the patient's first beta blocker dispensing. As you can see, I've split the data for people who used BBs (patient 476 is the only one to have used a BB in this sample data), so in row 9 patient 476 is counted as using a BB between 8.85 years and 10.82 years. I've then created a variable (the second to last column in this sample data) to run a Cox model on, representing the time-varying nature of BB use (code if for STATA, sorry R users):
gen timetofbetablockerana=1 if _t0>=timetofbetablocker & timetofbetablocker!=.
replace timetofbetablockerana=0 if timetofbetablockerana==.
I can then run a simple (unadjusted) Cox model for BBs using stcox timetofbetablockerana
A question I have been grappling with for a while now is how I adequately test the PH assumption with this time-varying covariate. I don't think a simple estat phtest (testing the proportional-hazards assumption on the basis of Schoenfeld residuals) in STATA suffices for this, because the variable is time-varying. In slide 32 of this presentation (https://ms.uky.edu/~mai/sta635/Cox%20model.pdf), they suggest interacting the time-varying covariate with time itself and then testing the assumption on this variable. So, I was thinking of interacting 'timetofbetablockerana' with 'timetofbetablocker' to allow the value of the analysis variable to vary based on when people started using BBs, and then including this interaction term in the model. e.g, gen interaction= timetofbetablocker* timetofbetablockerana, replace interaction=0 if interaction==., and then stcox timetofbetablockerana interaction and estat phtest, detail to test the assumption on the interaction term.
Is anyone able to let me know if I'm on the right track here? If this isn't correct, does anyone have any other ideas/suggestions on how I could go about this? Further, even with this time-varying covariate in the model, if I were to test the PH assumption on time-independent/fixed covariates (which are additionally included in the fully adjusted model), would I simply go about it the usual way, even in the presence of time-varying covariates in the same model?

@on this site only works for individuals who are already in the comment thread. I saw this question anyway, however. – EdM Nov 18 '23 at 19:25cox.zph()function in R has atermsargument that allows for a joint test over all levels of a multi-level categorical predictor; the smoothed plot of residuals then evaluates the entire linear predictor associated with all levels together. You might ask a STATA help group if that's available in that software. – EdM Nov 22 '23 at 14:48