Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • cox proportional hazard ratio with time varying covariate

    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

  • #2
    Since nobody has responded, here's my suggestion that I believe does the job but might also encourage better solutions. I modified your data to make stage missing for observation 13, so as to illustrate that the code works how I assume you would like.

    Code:
    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 . 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
    sort id pouchage_years
    by id: generate stagex=stage if _n==1
    by id: replace stagex=max(stage[_n],stagex[_n-1]) if _n!=1
    Here's the result:

    Code:
    . list observation id pouchage_years stage stagex, sepby(id)
    
         +-------------------------------------------+
         | observ~n   id   poucha~s   stage   stagex |
         |-------------------------------------------|
      1. |        1    1          7       .        . |
      2. |        2    1          8       .        . |
      3. |        3    1          9       2        2 |
      4. |        4    1         10       2        2 |
      5. |        5    1         11       2        2 |
      6. |        7    1         12       3        3 |
      7. |        8    1         13       3        3 |
      8. |       10    1         13       4        4 |
      9. |       11    1         14       3        4 |
     10. |       12    1         14       3        4 |
     11. |       13    1         15       .        4 |
     12. |       14    1         16       3        4 |
         |-------------------------------------------|
     13. |       15    2          4       0        0 |
     14. |       16    2          5       1        1 |
     15. |       17    2          6       1        1 |
     16. |       18    2          7       1        1 |
     17. |       19    2          8       2        2 |
     18. |       20    2         10       2        2 |
     19. |       21    2         12       1        2 |
         +-------------------------------------------+
    Yes, it's possible to include multiple time-varying effects in a Cox model. There's an example in the help file:

    Code:
    stcox age, tvc(drug1 drug2) texp(exp(-0.35*_t))
    I believe that when using tvc() the functional form of the non-proportionality (specified in texp()) must be assumed to be the same for all time-varying effects. That is, I may be wrong but I don't think you can specify something like the following

    Code:
    stcox age, tvc(drug1 drug2) texp(exp(-0.35*_t) _t)
    You can also model multiple time-varying effects by using -stsplit- to split the data. There is an example in the manual (page 81 of the st manual in version 16) where the first model specified above is estimated after splitting rather than using tvc(). When splitting you can use a different functional form for each of the time-varying effects.

    Comment


    • #3
      Dear Paul,

      Very many thanks for this. The first codes you have provided worked beautifully.

      I am now trying to do the cox regression.

      With respect to the time- varying covariates I note that you have put -0.35 into the model? I have seen this in the handbook also.... but I have no idea how I would work it out for my own data.

      Do you have any suggestions? and excuse my ignorance.

      Many thanks,

      ROshani

      Comment

      Working...
      X