Announcement

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

  • Comparison of margins after stcox

    I have run the following:
    Code:
    stset et
    . stcox i.x1 i.x2, nolog
    
            Failure _d: 1 (meaning all fail)
      Analysis time _t: et
    
    Cox regression with Breslow method for ties
    
    No. of subjects =     96                                Number of obs =     96
    No. of failures =     96
    Time at risk    = 46,172
                                                            LR chi2(4)    =  41.62
    Log likelihood = -324.79515                             Prob > chi2   = 0.0000
    
    ------------------------------------------------------------------------------
              _t | Haz. ratio   Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
              x1 |
             4w  |      1.000  (base)
             6w  |      0.387      0.118  -3.1094   0.002        0.213       0.704
             8w  |      0.264      0.086  -4.0927   0.000        0.140       0.500
            10w  |      0.126      0.043  -6.0467   0.000        0.064       0.246
                 |
              x2 |
              N  |      1.000  (base)
              Y  |      0.508      0.118  -2.9054   0.004        0.322       0.802
    ------------------------------------------------------------------------------
    
    . margins x1, over(x2)
    
    Predictive margins                                          Number of obs = 96
    Model VCE: OIM
    
    Expression: Predicted hazard ratio, predict()
    Over:       x2
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
           x2#x1 |
           N#4w  |      1.000          .        .       .            .           .
           N#6w  |      0.387      0.118   3.2760   0.001        0.155       0.619
           N#8w  |      0.264      0.086   3.0758   0.002        0.096       0.433
          N#10w  |      0.126      0.043   2.9180   0.004        0.041       0.210
           Y#4w  |      0.508      0.118   4.2896   0.000        0.276       0.740
           Y#6w  |      0.197      0.083   2.3670   0.018        0.034       0.359
           Y#8w  |      0.134      0.061   2.1952   0.028        0.014       0.254
          Y#10w  |      0.064      0.029   2.2087   0.027        0.007       0.121
    ------------------------------------------------------------------------------
    and I would like to compare the margin Y#10w with N#10w but I cannot figure out how to do it. I tried
    Code:
    . lincom _b[N#4w] - _b[Y#4w]
    [N#4w] not found
    and various combinations with no success.

    I would be grateful for any help.

    Eddy
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte x1 long x2 double et
    1 1  185
    1 1  285
    1 2  487
    1 2  453
    1 1  395
    1 1  483
    1 1  356
    1 1  168
    1 1  312
    1 2  283
    1 2  343
    1 1  303
    1 2  483
    1 1  182
    1 1  168
    1 2  640
    1 1  334
    1 2  437
    1 1  364
    1 1  262
    1 1  343
    1 1  325
    1 2  371
    2 1  465
    2 2  439
    2 2  608
    2 2  335
    2 1  355
    2 1  412
    2 1  316
    2 1  455
    2 1  435
    2 1  438
    2 1  592
    2 1  437
    2 1  208
    2 2  291
    2 1  578
    2 1  393
    2 2  565
    2 1  503
    2 1  175
    2 2  574
    2 2  524
    2 1  636
    2 2  545
    2 2  336
    2 2  391
    3 1  353
    3 1  543
    3 1  343
    3 2  593
    3 1  381
    3 1  484
    3 1  477
    3 1  393
    3 1  559
    3 1  479
    3 1  431
    3 1  411
    3 2  761
    3 1  398
    3 2  492
    3 2  298
    3 1  693
    3 1  536
    3 1  923
    3 1  529
    3 2  395
    3 1  397
    3 1  364
    4 1  290
    4 2  954
    4 1  473
    4 1  586
    4 2  951
    4 2 1060
    4 1  776
    4 2  693
    4 1 1027
    4 1  375
    4 1  416
    4 1  302
    4 1  896
    4 1  498
    4 1  580
    4 2  877
    4 2  573
    4 1  424
    4 1  566
    4 2  511
    4 1  873
    4 2  513
    4 2  540
    4 1  549
    4 1  668
    end
    label values x1 grp
    label def grp 1 "4w", modify
    label def grp 2 "6w", modify
    label def grp 3 "8w", modify
    label def grp 4 "10w", modify
    label values x2 ext
    label def ext 1 "N", modify
    label def ext 2 "Y", modify


  • #2
    Code:
    margins x1, over(x2) post
    matrix list e(b)
    lincom _b[1.x2#1.x1] - _b[2.x2#1.x1]
    Note: You don't need to actually run the -matrix list e(b)- command. That's just there so you can see what the actual names -margins- uses are.
    Though, in general, the principal is that the value labels you assigned to the variables are not used in the naming of the coefficients.

    Comment


    • #3
      I have found that mlincom, spost13_ado from https://jslsoc.sitehost.iu.edu/stata, simplifies identifying the coefficients:

      Code:
      . lincom _b[1.x2#1.x1] - _b[2.x2#1.x1]
      
       ( 1)  1bn.x2#1bn.x1 - 2.x2#1bn.x1 = 0
      
      ------------------------------------------------------------------------------
                   | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
      -------------+----------------------------------------------------------------
               (1) |      0.492      0.118   4.1548   0.000        0.260       0.724
      ------------------------------------------------------------------------------
      
      . mlincom (1-5)
      
                   |   lincom    pvalue        ll        ul 
      -------------+---------------------------------------
                 1 |    0.492     0.000     0.260     0.724

      Comment


      • #4
        Thank you both for your help.

        Comment

        Working...
        X