Announcement

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

  • How to get stratified adjusted HR after Cox regression with interaction term without running the model twice

    Dear Statalist

    I have the following dataset with three binary variables, i.e. outcome (death after six months), older_65 (age above 65) and sex, as well as two continous variable, follow_up_days and age_years:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(age_years follow_up_days) byte(outcome older_65 sex_female1)
    72 358 0 1 0
    72 363 0 1 0
    76 357 0 1 0
    87 209 1 1 0
    66 363 0 1 0
    80 359 0 1 0
    61 360 0 0 0
    73 358 0 1 1
    81 359 1 1 0
    end
    label values outcome yes_no_lab
    label values sex_female1 sex_lab
    label values older_65 yes_no_lab
    label def yes_no_lab 0 "No", modify
    label def yes_no_lab 1 "Yes", modify
    label def sex_lab 0 "Male", modify
    label def sex_lab 1 "Female", modify

    I wonder if there is a better way to obtain the HR for female vs. male in each age group than running the model twice and changing the baseline category. Margins is kind of tricky after stcox (see for instance https://www.statalist.org/forums/for...ns-after-stcox),

    Code:
    stset follow, failure(outcome)
    stcox i.sex_female1##i.older_65 age_years
    
    Cox regression with Breslow    method    for ties
    
    No. of subjects =   1,746                Number of obs =  1,746
    No. of failures =     449
    Time at risk    = 535,017
                    LR chi2(4)    = 121.65
    Log likelihood = -3227.9518                Prob > chi2   = 0.0000
    
                    
    _t  Haz.    ratio    Std. err.    z    P>z     [95% conf. interval]
                    
    older_65
    No    1.00    (base)
    Yes    1.87    0.24    4.95    0.000         1.46        2.39
    
    sex_female1
    Male    1.00    (base)
    Female    0.77    0.11    -1.77    0.077         0.58        1.03
    
    older_65#sex_female1
    Yes#Female    0.87    0.17    -0.70    0.481         0.60        1.27
    
    age_years    1.03    0.00    7.40    0.000         1.02        1.04
    => I obtain the age-adjusted HR comparing females with males in the older_65 == 0 (baseline group) in row for sex_female.

    After changing the baseline category of older_65, I can obtain the age-adjusted HR comparing females with males in the older_65 == 1 (new baseline category) group (output omitted).
    Code:
    stcox i.sex_female1##ib1.older_65 age_years
    When the model takes a lot of time to calculate, it is odd to run it twice. Is there another way e.g. with lincom?

    Thank you in advance for your help.
    Martin

  • #2
    The hazard ratios are just the exponentiated coefficients. Even though Stata displays hazard ratios, what are stored are the coefficients. With a binary variable, changing the base simply has the effect of flipping the sign. The same way as you can say that "X" costs $10 dollars more than "Y", the converse is that "Y" costs $10 less than "X".

    Code:
    webuse stan3, clear
    stset
    set seed 09202023
    gen surg2= runiformint(0,1)
    stcox age i.transplant##ib0.surg2 year
    
    display exp(-_b[1.surg2])
    display exp(-_b[1.transplant#1.surg2])
    
    stcox age i.transplant##ib1.surg2 year
    Res.:

    Code:
    . stcox age i.transplant##ib0.surg2 year
    
             failure _d:  died
       analysis time _t:  t1
                     id:  id
    
    Iteration 0:   log likelihood = -298.31514
    Iteration 1:   log likelihood = -277.06683
    Iteration 2:   log likelihood =  -274.8131
    Iteration 3:   log likelihood = -274.81058
    Iteration 4:   log likelihood = -274.81058
    Refining estimates:
    Iteration 0:   log likelihood = -274.81058
    
    Cox regression with Breslow method for ties
    
    No. of subjects =          103                  Number of obs    =         172
    No. of failures =           75
    Time at risk    =      31938.1
                                                    LR chi2(5)       =       47.01
    Log likelihood  =   -274.81058                  Prob > chi2      =      0.0000
    
    ----------------------------------------------------------------------------------
                  _t | Haz. Ratio   Std. err.      z    P>|z|     [95% conf. interval]
    -----------------+----------------------------------------------------------------
                 age |   1.060381   .0158288     3.93   0.000     1.029806    1.091863
        1.transplant |   .1751913   .0618293    -4.94   0.000     .0877208    .3498827
             1.surg2 |   1.065129   .3963012     0.17   0.865     .5136846    2.208552
                     |
    transplant#surg2 |
                1 1  |   .9888049   .4738387    -0.02   0.981     .3865555    2.529352
                     |
                year |   .8964443   .0597319    -1.64   0.101     .7866943    1.021505
    ----------------------------------------------------------------------------------
    
    . 
    . 
    . 
    . display exp(-_b[1.surg2])
    .93885358
    
    . 
    . display exp(-_b[1.transplant#1.surg2])
    1.0113219
    
    . 
    . 
    . 
    . stcox age i.transplant##ib1.surg2 year
    
             failure _d:  died
       analysis time _t:  t1
                     id:  id
    
    Iteration 0:   log likelihood = -298.31514
    Iteration 1:   log likelihood = -277.06683
    Iteration 2:   log likelihood =  -274.8131
    Iteration 3:   log likelihood = -274.81058
    Iteration 4:   log likelihood = -274.81058
    Refining estimates:
    Iteration 0:   log likelihood = -274.81058
    
    Cox regression with Breslow method for ties
    
    No. of subjects =          103                  Number of obs    =         172
    No. of failures =           75
    Time at risk    =      31938.1
                                                    LR chi2(5)       =       47.01
    Log likelihood  =   -274.81058                  Prob > chi2      =      0.0000
    
    ----------------------------------------------------------------------------------
                  _t | Haz. Ratio   Std. err.      z    P>|z|     [95% conf. interval]
    -----------------+----------------------------------------------------------------
                 age |   1.060381   .0158288     3.93   0.000     1.029806    1.091863
        1.transplant |     .17323   .0658006    -4.62   0.000     .0822807    .3647103
             0.surg2 |   .9388536   .3493182    -0.17   0.865     .4527853     1.94672
                     |
    transplant#surg2 |
                1 0  |   1.011322   .4846289     0.02   0.981     .3953582     2.58695
                     |
                year |   .8964443   .0597319    -1.64   0.101     .7866943    1.021505
    ----------------------------------------------------------------------------------

    Comment


    • #3
      Thank you, Andrew!
      Works perfectly.

      Comment

      Working...
      X