Announcement

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

  • Compile / Export all table values form -estat phtest, detail-

    Dear all,

    I am running several Cox PH survival models and use Schoenfeld residuals as a first layer of tests for the proportional-hazard assumption. In the tests, I am not only interested in the global test results, but would like to report all values of each individual variable. The Problem: As I am running at least one dozen tests for several models I would like to / will need to compile and export all tables in to *.tex files automaticially to stay efficient (just like in compling regression tables via -estout-, say). However, it seems like I can not access these values from Stata's storage (see -ereturn list- in the code below).

    Question: Is there a solution to fetch all values reported in -estat phtest, detail- and compile / export then into a (neat) table, at best in .tex format?

    Here a sample code and data set for my issue:

    Code:
    version 14
    
    webuse drugtr
    
    stcox drug age
    
    estat phtest, detail
    
    ereturn list // see for info
    
    // compile entire table to *.tex
    Thanks a lot for your help in advance,
    Michael

  • #2
    Most Stata commands store results in r() or e(), so do check

    Code:
    ereturn list
    and

    Code:
    return list
    You can install esttab from Stata Journal/ SSC that will allow you to export results in tex format. For your example,

    Code:
    . webuse drugtr
    (Patient Survival in Drug Trial)
    
    .
    . stcox drug age
    
             failure _d:  died
       analysis time _t:  studytime
    
    Iteration 0:   log likelihood = -99.911448
    Iteration 1:   log likelihood = -83.551879
    Iteration 2:   log likelihood = -83.324009
    Iteration 3:   log likelihood = -83.323546
    Refining estimates:
    Iteration 0:   log likelihood = -83.323546
    
    Cox regression -- Breslow method for ties
    
    No. of subjects =           48                  Number of obs    =          48
    No. of failures =           31
    Time at risk    =          744
                                                    LR chi2(2)       =       33.18
    Log likelihood  =   -83.323546                  Prob > chi2      =      0.0000
    
    ------------------------------------------------------------------------------
              _t | Haz. Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
            drug |   .1048772   .0477017    -4.96   0.000     .0430057    .2557622
             age |   1.120325   .0417711     3.05   0.002     1.041375     1.20526
    ------------------------------------------------------------------------------
    
    .
    .
    .
    . estat phtest, detail
    
          Test of proportional-hazards assumption
    
          Time:  Time
          ----------------------------------------------------------------
                      |       rho            chi2       df       Prob>chi2
          ------------+---------------------------------------------------
          drug        |      0.00949         0.00        1         0.9603
          age         |     -0.11758         0.42        1         0.5168
          ------------+---------------------------------------------------
          global test |                      0.43        2         0.8064
          ----------------------------------------------------------------
    
    
    . return list
    
    scalars:
                      r(p) =  .8064027006341521
                     r(df) =  2
                   r(chi2) =  .4303440653399125
    
    matrices:
                 r(phtest) :  2 x 4
    
    . mat list r(phtest)
    
    r(phtest)[2,4]
                 rho        chi2          df           p
    drug   .00948669   .00248244           1   .96026257
     age  -.11758379   .42020368           1   .51683543
    
    . mat R= r(phtest)
    
    . esttab mat(R), tex
    
    \begin{tabular}{l*{4}{c}}
    \hline\hline
                &           R&            &            &            \\
                &         rho&        chi2&          df&           p\\
    \hline
    drug        &    .0094867&    .0024824&           1&    .9602626\\
    age         &   -.1175838&    .4202037&           1&    .5168354\\
    \hline\hline
    \end{tabular}

    Comment


    • #3
      Thanks a lot, Andrew. I'll give it a try.

      Comment


      • #4
        The command works great, but misses the last line with the global test. How do I add a line with the three variables from the global test to my matrix?

        Comment


        • #5
          Code:
          webuse drugtr, clear
          stcox drug age
          estat phtest, detail
          mat R= r(phtest)
          mat g= .a,  r(chi2), r(df), r(p)
          mat rowname g = "global test"
          mat R= R\g
          mat l R

          Res.:

          Code:
          . mat l R
          
          R[3,4]
                              rho        chi2          df           p
                 drug   .00948669   .00248244           1   .96026257
                  age  -.11758379   .42020368           1   .51683543
          global test          .a   .43034407           2    .8064027

          Comment


          • #6
            Thanks again, Andrew, for this awesome help. That´s perfect. Much appreciated.
            Best, Michael

            Comment

            Working...
            X