UCLA Academic Technology Services HomeServicesClassesContactJobs

Stata FAQ
How can I get a Somers' D after logistic regression in Stata?

Recently we received the following question: The output from SAS proc logistic gives a values for Somers' D. How can I get this using Stata?

The Somers' D, in logistic regression, provides an estimate of the rank correlation of the observed binary response variable and the predicted probabilities. Thus, it can be used as an indicator of model fit.

Its not difficult to get a Somers' D in Stata once you download the user contributed program somersd written by Roger Newsom. To get the program just type, ssc install somersd, in Stata's command window and follow the prompts to download the program.

Once you have downloaded somersd, run your logistic regression, compute the predicted probability and then run somersd with your binary response variable and the predicted probability.

Example

We will use the hsb2 dataset for this example. It doesn't have a good binary response variable so we will create one by dichotomizing write at the value 60 and calling it honors (for honors English). Then we will use it in a logistic regression with read, female and prog (the type of program each student is in) as predictors. After the logit command we will use predict to get the predicted probabilities.

use http://www.ats.ucla.edu/stat/data/hsb2, clear

generate honors=write>=60  /* create binary response variable */

xi: logit honors read female i.prog

i.prog            _Iprog_1-3          (naturally coded; _Iprog_1 omitted)

Logistic regression                               Number of obs   =        200
                                                  LR chi2(4)      =      62.20
                                                  Prob > chi2     =     0.0000
Log likelihood = -84.542348                       Pseudo R2       =     0.2689

------------------------------------------------------------------------------
      honors |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        read |   .1352861   .0242218     5.59   0.000     .0878123      .18276
      female |    1.08343   .4094357     2.65   0.008     .2809511    1.885909
    _Iprog_2 |   .5559416   .5053125     1.10   0.271    -.4344527    1.546336
    _Iprog_3 |   .0016408   .6611702     0.00   0.998    -1.294229     1.29751
       _cons |   -9.41691   1.481922    -6.35   0.000    -12.32142   -6.512397
------------------------------------------------------------------------------

predict pprob
Now that we have the predicted probabilities, pprob, we can run somersd.
somersd honors pprob

Somers' D with variable: honors
Transformation: Untransformed
Valid observations: 200

Symmetric 95% CI
------------------------------------------------------------------------------
             |              Jackknife
      honors |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       pprob |   .6761648     .05778    11.70   0.000     .5629182    .7894115
------------------------------------------------------------------------------
The value of Somers' D is 0.676. We can compare this value of Somers' D to one from a model that uses only prog as a predictor.
xi: logit honors i.prog

i.prog            _Iprog_1-3          (naturally coded; _Iprog_1 omitted)

Logistic regression                               Number of obs   =        200
                                                  LR chi2(2)      =      16.15
                                                  Prob > chi2     =     0.0003
Log likelihood =  -107.5719                       Pseudo R2       =     0.0698

------------------------------------------------------------------------------
      honors |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    _Iprog_2 |   1.206168   .4577746     2.63   0.008     .3089465     2.10339
    _Iprog_3 |  -.3007542   .5988045    -0.50   0.615    -1.474389    .8728812
       _cons |  -1.691676   .4113064    -4.11   0.000    -2.497822   -.8855303
------------------------------------------------------------------------------

predict pprob2

(option pr assumed; Pr(honors))

somersd honors pprob2

Somers' D with variable: honors
Transformation: Untransformed
Valid observations: 200

Symmetric 95% CI
------------------------------------------------------------------------------
             |              Jackknife
      honors |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      pprob2 |   .3228084   .0737763     4.38   0.000     .1782095    .4674073
------------------------------------------------------------------------------
As you can see the Somers' D in this model is much smaller than in the previous one.

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.