UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Applied Longitudinal Data Analysis: Modeling Change and Event Occurrence
by Judith D. Singer and John B. Willett
Chapter 14:  Fitting Cox regression models

Table 14.1, page 525.
use http://www.ats.ucla.edu/stat/stata/examples/alda/data/rearrest, clear 

generate event = ~censor 
stset months, failure(event) 

     failure event:  event ~= 0 & event ~= .
obs. time interval:  (0, months]
 exit on or before:  failure
 
------------------------------------------------------------------------------
      194  total obs.
        0  exclusions
------------------------------------------------------------------------------
      194  obs. remaining, representing
      106  failures in single record/single failure data
 2678.456  total analysis time at risk, at risk from t =         0
                             earliest observed entry t =         0
                                  last observed exit t =        36
 
/* Model A */
stcox personal, nohr
 
Cox regression -- Breslow method for ties
 
No. of subjects =          194                     Number of obs   =       194
No. of failures =          106
Time at risk    =  2678.455851
                                                   LR chi2(1)      =      5.32
Log likelihood  =   -492.08392                     Prob > chi2     =    0.0210
 
------------------------------------------------------------------------------
          _t |
          _d |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    personal |   .4786654    .202482     2.36   0.018     .0818079    .8755229
------------------------------------------------------------------------------
 
test personal   /* wald test */
 
 ( 1)  personal = 0.0
 
           chi2(  1) =    5.59
         Prob > chi2 =    0.0181
 
/* Model B */
stcox property, nohr
 
Cox regression -- Breslow method for ties
 
No. of subjects =          194                     Number of obs   =       194
No. of failures =          106
Time at risk    =  2678.455851
                                                   LR chi2(1)      =     16.19
Log likelihood  =   -486.64864                     Prob > chi2     =    0.0000
 
------------------------------------------------------------------------------
          _t |
          _d |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    property |   1.194205   .3492838     3.42   0.001     .5096218    1.878789
------------------------------------------------------------------------------
 
test property   /* wald test */
 
 ( 1)  property = 0.0
 
           chi2(  1) =   11.69
         Prob > chi2 =    0.0006
 
/* Model C */
stcox cage, nohr
 
Cox regression -- Breslow method for ties
 
No. of subjects =          194                     Number of obs   =       194
No. of failures =          106
Time at risk    =  2678.455851
                                                   LR chi2(1)      =     22.93
Log likelihood  =   -483.27909                     Prob > chi2     =    0.0000
 
------------------------------------------------------------------------------
          _t |
          _d |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        cage |  -.0680667   .0156264    -4.36   0.000    -.0986939   -.0374394
------------------------------------------------------------------------------
 
test cage   /* wald test */
 
 ( 1)  cage = 0.0
 
           chi2(  1) =   18.97
         Prob > chi2 =    0.0000
 
/* Model D */
stcox personal property cage, nohr
 
Cox regression -- Breslow method for ties
 
No. of subjects =          194                     Number of obs   =       194
No. of failures =          106
Time at risk    =  2678.455851
                                                   LR chi2(3)      =     38.91
Log likelihood  =   -475.29169                     Prob > chi2     =    0.0000
 
------------------------------------------------------------------------------
          _t |
          _d |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    personal |   .5686725   .2051984     2.77   0.006      .166491     .970854
    property |   .9354007   .3508835     2.67   0.008     .2476817     1.62312
        cage |  -.0666248   .0167731    -3.97   0.000    -.0994995   -.0337501
------------------------------------------------------------------------------

test personal   /* wald test */
 
 ( 1)  personal = 0.0
 
           chi2(  1) =    7.68
         Prob > chi2 =    0.0056
 
test property   /* wald test */
 
 ( 1)  property = 0.0

           chi2(  1) =    7.11
         Prob > chi2 =    0.0077
 
test cage   /* wald test */
 
 ( 1)  cage = 0.0
 
           chi2(  1) =   15.78
         Prob > chi2 =    0.0001
         
/* Likelihood ratio tests */
lrtest, saving(0) 
quietly stcox property cage, nohr  /* testing personal */ 
lrtest

Cox:  likelihood-ratio test                           chi2(1)     =       7.27
                                                      Prob > chi2 =     0.0070
 
quietly stcox personal cage, nohr  /* testing property */ 
lrtest
 
Cox:  likelihood-ratio test                           chi2(1)     =       9.14
                                                      Prob > chi2 =     0.0025
 
quietly stcox personal property, nohr  /* testing cage */ 
lrtest
 
Cox:  likelihood-ratio test                           chi2(1)     =      18.28
                                                      Prob > chi2 =     0.0000
Table 14.2, page 533.

Use predict after stcox personal property cage.

Note: Observations are in numerical id order, not the order shown in the book.

predict risk 
list id personal property cage risk months censor if inlist(id,22,8,187,26,5,130,106,33)
 
            id   personal   property       cage       risk     months     censor
  5.         5          1          1  -7.164588    7.25298   .2956879          0
  8.         8          1          1   22.45074   1.008332     .62423          1
 22.        22          0          0   .2577249   .9829757   1.708419          1
 26.        26          0          1  -7.301481   4.144825   2.365503          0
 33.        33          1          0   27.06129   .2910442   2.792608          1
106.       106          0          0   16.20297   .3397587    11.6961          0
130.       130          0          1   22.39051   .5732906   15.96715          1
187.       187          1          0  -7.200181   2.853034         36          1


How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California