Dear Stata community,

I am struggling with cox proportional hazard ratio.

I was wondering if you could please help on two things:

Here is an example of my data:
​​​​​​
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(observation id pouchage_years stage) float(var5 var6 var7)
 1 1  7 . 1 0 25
 2 1  8 . 1 0 26
 3 1  9 2 1 0 27
 4 1 10 2 1 0 28
 5 1 11 2 1 1 29
 7 1 12 3 1 1 40
 8 1 13 3 1 1 41
10 1 13 4 1 1 41
11 1 14 3 1 1 42
12 1 14 3 1 1 42
13 1 15 3 1 1 43
14 1 16 3 1 1 44
15 2  4 0 0 0 35
16 2  5 1 0 0 36
17 2  6 1 0 0 37
18 2  7 1 0 0 38
19 2  8 2 0 0 39
20 2 10 2 0 0 41
21 2 12 1 0 0 43
end
var6 is outcome data for the event of interest. pouchage_years is the time variable. id is the id of the participant.
var5 is categorical gender data.

My problem is:
1. the "stage" variable. Clinically i know is time varying... but sometimes due to an intervention that we perform the stage goes down. But this is misleading for what I am looking at - so what I would like to do is for the highest "stage" by the paritcipant I would like to keep it at the maximum level there-after (i.e.in participant one: I don't want it to drop from 4 back down to 3... i would like to have the 4 continue for the rest of the observations. What code do you recommend I use to generate this new variable please? I have tried and failed.

2. I would then like to perform a cox proportional hazards ratio for this dataset (I have over 2000 observations for 250 people). Event is var 6. In the model I would like to put some variables that do not change with time e.g. var5 (gender) and I have others which I have not put in this dataexample. I would also lile to add into the model variables that DO change with time. such as biological age of participant (var7), and the new "stage" variable that I have generated from problem one.

Is there a way to put more than one time varying covariates into the model. When I tried i got an error message.

I would be grateful for any advice.

With appreciation,

Roshani