UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Applied Logistic Regression, Second Edition, by Hosmer and Lemeshow
Chapter 6: Application of Logistic Regression with Different Sampling Models

The examples below use Stata 7 or 8.  If you are using Stata version 9, please see this page.

The data files used for the examples in this text can be downloaded in a .zip file from the Wiley Publications website.  You can then use a program such as WinZip to unzip the data files.  If you need assistance getting data into Stata, please see our Stata Class Notes, especially the unit on Entering Data.  (NOTE:  The *.dat files are the data files, and the *.txt files contain the codebook information.)

Table 6.2, page 216.
NOTE: You need to increase the amount of memory available to Stata before opening this data file because it is so large.
set mem 5m
(5120k)

use nhanes3.dta, clear
xi: svylogit HBP HSAGEIR HSSEX I.DMARACER BMPWTLBS BMPHTIN I.SMOKE 
       [pweight=WTPFHX6], strata(SDPSTRA6) psu(SDPPSU6)
       
I.DMARACER        _IDMARACER_1-3      (naturally coded; _IDMARACER_1 omitted)
I.SMOKE           _ISMOKE_1-3         (naturally coded; _ISMOKE_1 omitted)

Survey logistic regression

pweight:  WTPFHX6                                 Number of obs    =     16963
Strata:   SDPSTRA6                                Number of strata =        49
PSU:      SDPPSU6                                 Number of PSUs   =        98
                                                  Population size  = 1.769e+08
                                                  F(   8,     42)  =    193.50
                                                  Prob > F         =    0.0000

------------------------------------------------------------------------------
         HBP |      Coef.    Std. Err.      t    P>|t|    [95% Conf. Interval]
-------------+----------------------------------------------------------------
     HSAGEIR |   .0807254    .0024847    32.49   0.000    .0757323    .0857185
       HSSEX |   .2040417    .0754752     2.70   0.009    .0523686    .3557149
_IDMARACER_2 |    .558488    .0743918     7.51   0.000    .4089921    .7079839
_IDMARACER_3 |   .0436902    .3004571     0.15   0.885   -.5601009    .6474814
    BMPWTLBS |   .0116062    .0008349    13.90   0.000    .0099284     .013284
     BMPHTIN |  -.0592606    .0126097    -4.70   0.000   -.0846008   -.0339204
   _ISMOKE_2 |  -.0764019    .0949624    -0.80   0.425   -.2672361    .1144323
   _ISMOKE_3 |   .0610105    .1050502     0.58   0.564   -.1500959    .2721169
       _cons |  -4.257218    .8040119    -5.29   0.000    -5.87294   -2.641496
------------------------------------------------------------------------------
Table 6.3 , page 218.
NOTE: The strata option identifies the variable that stratifies the data. The variable listed in the psu option contains the identifier for the primary sampling units.
svylogit HBP HSAGEIR HSSEX _IDMARACER_2 _IDMARACER_3 BMPWTLBS BMPHTIN 
           [pweight=WTPFHX6], strata(SDPSTRA6) psu(SDPPSU6)

Survey logistic regression

pweight:  WTPFHX6                                 Number of obs    =     16964
Strata:   SDPSTRA6                                Number of strata =        49
PSU:      SDPPSU6                                 Number of PSUs   =        98
                                                  Population size  = 1.769e+08
                                                  F(   6,     44)  =    205.76
                                                  Prob > F         =    0.0000

------------------------------------------------------------------------------
         HBP |      Coef.    Std. Err.      t    P>|t|    [95% Conf. Interval]
-------------+----------------------------------------------------------------
     HSAGEIR |   .0799522    .0026616    30.04   0.000    .0746036    .0853008
       HSSEX |   .1938372    .0790581     2.45   0.018    .0349641    .3527104
_IDMARACER_2 |   .5715161    .0709902     8.05   0.000    .4288559    .7141762
_IDMARACER_3 |   .0519777    .3006959     0.17   0.863   -.5522932    .6562486
    BMPWTLBS |   .0114421    .0008405    13.61   0.000    .0097531    .0131311
     BMPHTIN |  -.0589891    .0126859    -4.65   0.000   -.0844824   -.0334958
       _cons |  -4.211455    .7940002    -5.30   0.000   -5.807058   -2.615852
------------------------------------------------------------------------------
Table 6.43, page 219.
logit HBP HSAGEIR HSSEX  _IDMARACER_2  _IDMARACER_3 BMPWTLBS BMPHTIN

Iteration 0:   log likelihood = -8602.8989
Iteration 1:   log likelihood = -6870.2255
Iteration 2:   log likelihood = -6671.2868
Iteration 3:   log likelihood = -6663.7359
Iteration 4:   log likelihood = -6663.7081

Logit estimates                                   Number of obs   =      16964
                                                  LR chi2(6)      =    3878.38
                                                  Prob > chi2     =     0.0000
Log likelihood = -6663.7081                       Pseudo R2       =     0.2254

------------------------------------------------------------------------------
         HBP |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     HSAGEIR |   .0696379   .0013966    49.86   0.000     .0669007    .0723751
       HSSEX |   .0904745   .0613365     1.48   0.140    -.0297429    .2106919
_IDMARACER_2 |   .4765584   .0509377     9.36   0.000     .3767225    .5763944
_IDMARACER_3 |   .0916109   .1430926     0.64   0.522    -.1888453    .3720672
    BMPWTLBS |   .0083715   .0006091    13.74   0.000     .0071776    .0095654
     BMPHTIN |  -.0451575   .0085049    -5.31   0.000    -.0618268   -.0284882
       _cons |  -3.871509    .529282    -7.31   0.000    -4.908883   -2.834135
------------------------------------------------------------------------------
Table 6.5, page 221.
Design-based analysis:
svylogit HBP HSAGEIR HSSEX _IDMARACER_2 _IDMARACER_3 BMPWTLBS 
           BMPHTIN [pweight=WTPFHX6], strata(SDPSTRA6) psu(SDPPSU6) or

Survey logistic regression

pweight:  WTPFHX6                                 Number of obs    =     16964
Strata:   SDPSTRA6                                Number of strata =        49
PSU:      SDPPSU6                                 Number of PSUs   =        98
                                                  Population size  = 1.769e+08
                                                  F(   6,     44)  =    205.76
                                                  Prob > F         =    0.0000

------------------------------------------------------------------------------
         HBP | Odds Ratio    Std. Err.      t    P>|t|    [95% Conf. Interval]
-------------+----------------------------------------------------------------
     HSAGEIR |   1.083235    .0028831    30.04   0.000    1.077457    1.089045
       HSSEX |   1.213899    .0959685     2.45   0.018    1.035583    1.422919
_IDMARACER_2 |    1.77095    .1257201     8.05   0.000      1.5355    2.042503
_IDMARACER_3 |   1.053352    .3167386     0.17   0.863    .5756282    1.927548
    BMPWTLBS |   1.011508    .0008502    13.61   0.000    1.009801    1.013218
     BMPHTIN |    .942717    .0119592    -4.65   0.000    .9189878    .9670589
------------------------------------------------------------------------------
Model-based analysis:
logit HBP HSAGEIR HSSEX  _IDMARACER_2  _IDMARACER_3 BMPWTLBS BMPHTIN, or

Iteration 0:   log likelihood = -8602.8989
Iteration 1:   log likelihood = -6870.2255
Iteration 2:   log likelihood = -6671.2868
Iteration 3:   log likelihood = -6663.7359
Iteration 4:   log likelihood = -6663.7081

Logit estimates                                   Number of obs   =      16964
                                                  LR chi2(6)      =    3878.38
                                                  Prob > chi2     =     0.0000
Log likelihood = -6663.7081                       Pseudo R2       =     0.2254

------------------------------------------------------------------------------
         HBP | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     HSAGEIR |    1.07212   .0014973    49.86   0.000     1.069189    1.075059
       HSSEX |   1.094694   .0671447     1.48   0.140     .9706951    1.234532
_IDMARACER_2 |   1.610522   .0820362     9.36   0.000       1.4575     1.77961
_IDMARACER_3 |   1.095938   .1568206     0.64   0.522     .8279146     1.45073
    BMPWTLBS |   1.008407   .0006142    13.74   0.000     1.007203    1.009611
     BMPHTIN |   .9558469   .0081294    -5.31   0.000     .9400457    .9719138
------------------------------------------------------------------------------

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.