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 zip 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 4.1, page 105.
use "d:\hosmeruis.dta", clear logit dfree age Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -326.16602 Iteration 2: log likelihood = -326.16544 Logit estimates Number of obs = 575 LR chi2(1) = 1.40 Prob > chi2 = 0.2371 Log likelihood = -326.16544 Pseudo R2 = 0.0021 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | .0181723 .015344 1.18 0.236 -.0119014 .048246 _cons | -1.660226 .5110844 -3.25 0.001 -2.661933 -.6585194 ------------------------------------------------------------------------------ logit dfree age, or Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -326.16602 Iteration 2: log likelihood = -326.16544 Logit estimates Number of obs = 575 LR chi2(1) = 1.40 Prob > chi2 = 0.2371 Log likelihood = -326.16544 Pseudo R2 = 0.0021 ------------------------------------------------------------------------------ dfree | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | 1.018338 .0156254 1.18 0.236 .9881691 1.049429 ------------------------------------------------------------------------------ lrtest, saving(1) logit dfree Iteration 0: log likelihood = -326.86446 Logit estimates Number of obs = 575 LR chi2(0) = -0.00 Prob > chi2 = . Log likelihood = -326.86446 Pseudo R2 = -0.0000 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -1.068691 .095599 -11.18 0.000 -1.256061 -.88132 ------------------------------------------------------------------------------ lrtest, using(1) Logit: likelihood-ratio test chi2(1) = 1.40 Prob > chi2 = 0.2371 logit dfree beck Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -326.54634 Iteration 2: log likelihood = -326.54621 Logit estimates Number of obs = 575 LR chi2(1) = 0.64 Prob > chi2 = 0.4250 Log likelihood = -326.54621 Pseudo R2 = 0.0010 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- beck | -.008225 .0103428 -0.80 0.426 -.0284965 .0120464 _cons | -.9272829 .2003166 -4.63 0.000 -1.319896 -.5346696 ------------------------------------------------------------------------------ logit dfree beck, or Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -326.54634 Iteration 2: log likelihood = -326.54621 Logit estimates Number of obs = 575 LR chi2(1) = 0.64 Prob > chi2 = 0.4250 Log likelihood = -326.54621 Pseudo R2 = 0.0010 ------------------------------------------------------------------------------ dfree | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- beck | .9918087 .010258 -0.80 0.426 .9719057 1.012119 ------------------------------------------------------------------------------ lrtest, saving(2) logit dfree Iteration 0: log likelihood = -326.86446 Logit estimates Number of obs = 575 LR chi2(0) = -0.00 Prob > chi2 = . Log likelihood = -326.86446 Pseudo R2 = -0.0000 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -1.068691 .095599 -11.18 0.000 -1.256061 -.88132 ------------------------------------------------------------------------------ lrtest, using(2) Logit: likelihood-ratio test chi2(1) = 0.64 Prob > chi2 = 0.4250 logit dfree ndrugtx Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -321.33296 Iteration 2: log likelihood = -320.94874 Iteration 3: log likelihood = -320.94485 Iteration 4: log likelihood = -320.94485 Logit estimates Number of obs = 575 LR chi2(1) = 11.84 Prob > chi2 = 0.0006 Log likelihood = -320.94485 Pseudo R2 = 0.0181 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ndrugtx | -.0749582 .024681 -3.04 0.002 -.123332 -.0265844 _cons | -.7677805 .130326 -5.89 0.000 -1.023215 -.5123462 ------------------------------------------------------------------------------ logit dfree ndrugtx, or Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -321.33296 Iteration 2: log likelihood = -320.94874 Iteration 3: log likelihood = -320.94485 Iteration 4: log likelihood = -320.94485 Logit estimates Number of obs = 575 LR chi2(1) = 11.84 Prob > chi2 = 0.0006 Log likelihood = -320.94485 Pseudo R2 = 0.0181 ------------------------------------------------------------------------------ dfree | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ndrugtx | .9277822 .0228986 -3.04 0.002 .8839701 .9737658 ------------------------------------------------------------------------------ lrtest, saving(3) logit dfree Iteration 0: log likelihood = -326.86446 Logit estimates Number of obs = 575 LR chi2(0) = -0.00 Prob > chi2 = . Log likelihood = -326.86446 Pseudo R2 = -0.0000 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -1.068691 .095599 -11.18 0.000 -1.256061 -.88132 ------------------------------------------------------------------------------ lrtest, using(3) Logit: likelihood-ratio test chi2(1) = 11.84 Prob > chi2 = 0.0006 logit dfree ivhx2 ivhx3 Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -320.24478 Iteration 2: log likelihood = -320.18821 Iteration 3: log likelihood = -320.18821 Logit estimates Number of obs = 575 LR chi2(2) = 13.35 Prob > chi2 = 0.0013 Log likelihood = -320.18821 Pseudo R2 = 0.0204 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ivhx2 | -.4810199 .2657063 -1.81 0.070 -1.001795 .0397548 ivhx3 | -.7748382 .2165765 -3.58 0.000 -1.19932 -.3503561 _cons | -.6797242 .1417395 -4.80 0.000 -.9575285 -.4019198 ------------------------------------------------------------------------------ logit dfree ivhx2 ivhx3, or Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -320.24478 Iteration 2: log likelihood = -320.18821 Iteration 3: log likelihood = -320.18821 Logit estimates Number of obs = 575 LR chi2(2) = 13.35 Prob > chi2 = 0.0013 Log likelihood = -320.18821 Pseudo R2 = 0.0204 ------------------------------------------------------------------------------ dfree | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ivhx2 | .6181526 .164247 -1.81 0.070 .3672198 1.040556 ivhx3 | .4607783 .0997937 -3.58 0.000 .301399 .7044372 ------------------------------------------------------------------------------ lrtest, saving(4) logit dfree Iteration 0: log likelihood = -326.86446 Logit estimates Number of obs = 575 LR chi2(0) = -0.00 Prob > chi2 = . Log likelihood = -326.86446 Pseudo R2 = -0.0000 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -1.068691 .095599 -11.18 0.000 -1.256061 -.88132 ------------------------------------------------------------------------------ lrtest, using(4) Logit: likelihood-ratio test chi2(2) = 13.35 Prob > chi2 = 0.0013 logit dfree race Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -324.56405 Iteration 2: log likelihood = -324.55269 Iteration 3: log likelihood = -324.55269 Logit estimates Number of obs = 575 LR chi2(1) = 4.62 Prob > chi2 = 0.0315 Log likelihood = -324.55269 Pseudo R2 = 0.0071 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- race | .4591026 .2109763 2.18 0.030 .0455967 .8726085 _cons | -1.193922 .1141504 -10.46 0.000 -1.417653 -.9701919 ------------------------------------------------------------------------------ logit dfree race, or Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -324.56405 Iteration 2: log likelihood = -324.55269 Iteration 3: log likelihood = -324.55269 Logit estimates Number of obs = 575 LR chi2(1) = 4.62 Prob > chi2 = 0.0315 Log likelihood = -324.55269 Pseudo R2 = 0.0071 ------------------------------------------------------------------------------ dfree | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- race | 1.582653 .3339022 2.18 0.030 1.046652 2.393145 ------------------------------------------------------------------------------ lrtest, saving(5) logit dfree Iteration 0: log likelihood = -326.86446 Logit estimates Number of obs = 575 LR chi2(0) = -0.00 Prob > chi2 = . Log likelihood = -326.86446 Pseudo R2 = -0.0000 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -1.068691 .095599 -11.18 0.000 -1.256061 -.88132 ------------------------------------------------------------------------------ lrtest, using(5) Logit: likelihood-ratio test chi2(1) = 4.62 Prob > chi2 = 0.0315 logit dfree treat Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -324.28267 Iteration 2: log likelihood = -324.27534 Logit estimates Number of obs = 575 LR chi2(1) = 5.18 Prob > chi2 = 0.0229 Log likelihood = -324.27534 Pseudo R2 = 0.0079 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- treat | .437162 .1930633 2.26 0.024 .0587649 .8155591 _cons | -1.297816 .143296 -9.06 0.000 -1.578671 -1.016961 ------------------------------------------------------------------------------ logit dfree treat, or Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -324.28267 Iteration 2: log likelihood = -324.27534 Logit estimates Number of obs = 575 LR chi2(1) = 5.18 Prob > chi2 = 0.0229 Log likelihood = -324.27534 Pseudo R2 = 0.0079 ------------------------------------------------------------------------------ dfree | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- treat | 1.548307 .2989212 2.26 0.024 1.060526 2.260439 ------------------------------------------------------------------------------ lrtest, saving(6) logit dfree Iteration 0: log likelihood = -326.86446 Logit estimates Number of obs = 575 LR chi2(0) = -0.00 Prob > chi2 = . Log likelihood = -326.86446 Pseudo R2 = -0.0000 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -1.068691 .095599 -11.18 0.000 -1.256061 -.88132 ------------------------------------------------------------------------------ lrtest, using(6) Logit: likelihood-ratio test chi2(1) = 5.18 Prob > chi2 = 0.0229 logit dfree site Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -326.0327 Iteration 2: log likelihood = -326.0315 Logit estimates Number of obs = 575 LR chi2(1) = 1.67 Prob > chi2 = 0.1968 Log likelihood = -326.0315 Pseudo R2 = 0.0025 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- site | .2642236 .2034167 1.30 0.194 -.1344658 .662913 _cons | -1.15268 .1170732 -9.85 0.000 -1.382139 -.9232202 ------------------------------------------------------------------------------ logit dfree site, or Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -326.0327 Iteration 2: log likelihood = -326.0315 Logit estimates Number of obs = 575 LR chi2(1) = 1.67 Prob > chi2 = 0.1968 Log likelihood = -326.0315 Pseudo R2 = 0.0025 ------------------------------------------------------------------------------ dfree | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- site | 1.302419 .2649338 1.30 0.194 .8741828 1.940437 ------------------------------------------------------------------------------ lrtest, saving(7) logit dfree Iteration 0: log likelihood = -326.86446 Logit estimates Number of obs = 575 LR chi2(0) = -0.00 Prob > chi2 = . Log likelihood = -326.86446 Pseudo R2 = -0.0000 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -1.068691 .095599 -11.18 0.000 -1.256061 -.88132 ------------------------------------------------------------------------------ lrtest, using(7) Logit: likelihood-ratio test chi2(1) = 1.67 Prob > chi2 = 0.1968
Table 4.2, page 106.
logit dfree age ndrugtx ivhx2 ivhx3 race treat site Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -310.17928 Iteration 2: log likelihood = -309.62871 Iteration 3: log likelihood = -309.62413 Iteration 4: log likelihood = -309.62413 Logit estimates Number of obs = 575 LR chi2(7) = 34.48 Prob > chi2 = 0.0000 Log likelihood = -309.62413 Pseudo R2 = 0.0527 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | .0503708 .0173224 2.91 0.004 .0164196 .084322 ndrugtx | -.0615121 .0256311 -2.40 0.016 -.1117481 -.0112761 ivhx2 | -.6033296 .2872511 -2.10 0.036 -1.166331 -.0403278 ivhx3 | -.732722 .252329 -2.90 0.004 -1.227278 -.2381662 race | .2261295 .2233399 1.01 0.311 -.2116087 .6638677 treat | .4425031 .1992909 2.22 0.026 .0519002 .8331061 site | .1485845 .2172121 0.68 0.494 -.2771434 .5743125 _cons | -2.405405 .5548058 -4.34 0.000 -3.492805 -1.318006 ------------------------------------------------------------------------------
Figure 4.2, page 107.
lowess dfree age, gen(var3) logit nodraw graph twoway line var3 age, sort xlabel(20(10)50 56)
Table 4.3, page 107.
sort age generate age1 = (_n <= 148) generate age2 = (_n >= 149) & (_n <= 292) generate age3 = (_n >= 293) & (_n <= 458) generate age4 = (_n >= 459) logit dfree age2 age3 age4 ndrugtx ivhx2 ivhx3 race treat site Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -310.10643 Iteration 2: log likelihood = -309.5257 Iteration 3: log likelihood = -309.52103 Iteration 4: log likelihood = -309.52103 Logit estimates Number of obs = 575 LR chi2(9) = 34.69 Prob > chi2 = 0.0001 Log likelihood = -309.52103 Pseudo R2 = 0.0531 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age2 | -.165864 .2909137 -0.57 0.569 -.7360444 .4043163 age3 | .4693399 .27066 1.73 0.083 -.0611439 .9998237 age4 | .595771 .3124964 1.91 0.057 -.0167108 1.208253 ndrugtx | -.0587551 .0254688 -2.31 0.021 -.108673 -.0088371 ivhx2 | -.5545193 .2853626 -1.94 0.052 -1.11382 .0047811 ivhx3 | -.6725536 .2518601 -2.67 0.008 -1.16619 -.1789169 race | .2787172 .2238499 1.25 0.213 -.1600205 .7174549 treat | .4430577 .2000427 2.21 0.027 .0509812 .8351343 site | .1582001 .2188293 0.72 0.470 -.2706974 .5870976 _cons | -1.054837 .2705875 -3.90 0.000 -1.585179 -.5244956 ------------------------------------------------------------------------------
Figure 4.3, page 108.
preserve clear input age coef 24 0 30.5 -.165864 35.5 .4693399 47.5 .595771 end graph twoway scatter coef age, connect(l) ylabel(-.25(.25).75) xlabel(20(10)50) yline(0)
restore
Table 4.4, page 109.
fracpoly logit dfree age ndrugtx ivhx2 ivhx3 race treat site, degree(2) compare -> gen double Indru__1 = ndrugtx-4.543 if e(sample) ....... -> gen double Iage__1 = X^-2-.0954 if e(sample) -> gen double Iage__2 = X^3-33.96 if e(sample) (where: X = age/10) Logit estimates Number of obs = 575 LR chi2(8) = 34.96 Prob > chi2 = 0.0000 Log likelihood = -309.38436 Pseudo R2 = 0.0535 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- Iage__1 | -1.538626 4.575934 -0.34 0.737 -10.50729 7.43004 Iage__2 | .0116581 .0080977 1.44 0.150 -.0042132 .0275293 Indru__1 | -.0620596 .0257223 -2.41 0.016 -.1124744 -.0116447 ivhx2 | -.6057376 .2881578 -2.10 0.036 -1.170517 -.0409587 ivhx3 | -.7263554 .2525832 -2.88 0.004 -1.221409 -.2313014 race | .2282107 .224089 1.02 0.308 -.2109957 .6674171 treat | .4392589 .1996983 2.20 0.028 .0478573 .8306604 site | .1459101 .217491 0.67 0.502 -.2803644 .5721846 _cons | -1.082342 .2416317 -4.48 0.000 -1.555931 -.6087524 ------------------------------------------------------------------------------ Deviance: 618.7687. Best powers of age among 44 models fit: -2 3. Fractional polynomial model comparisons: --------------------------------------------------------------- age df Deviance Gain P(term) Powers --------------------------------------------------------------- Not in model 0 627.801 -- -- Linear 1 619.248 0.000 0.003 1 m = 1 2 618.882 0.366 0.545 3 m = 2 4 618.769 0.480 0.945 -2 3 ---------------------------------------------------------------
Figure 4.4, page 110.
Thanks to Joe Hilbe for the Stata code.
lowess dfree ndrugtx, logit gen(low) sort ndrugtx twoway line low ndrugtx, ylabel(-1.9305 -.7306) xlabel(0 1 2 5(5)40)
Table 4.5, page 110.
gen group = . replace group = 1 if ndrugtx==0 replace group = 2 if ndrugtx==1 | ndrugtx==2 replace group = 3 if ndrugtx>=3 & ndrugtx<=15 replace group = 4 if ndrugtx>15
xi: logit dfree age i.group i.ivhx race treat site
i.group _Igroup_1-4 (naturally coded; _Igroup_1 omitted) i.ivhx _Iivhx_1-3 (naturally coded; _Iivhx_1 omitted) Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -309.65414 Iteration 2: log likelihood = -309.31959 Iteration 3: log likelihood = -309.31915 Iteration 4: log likelihood = -309.31915 Logistic regression Number of obs = 575 LR chi2(9) = 35.09 Prob > chi2 = 0.0001 Log likelihood = -309.31915 Pseudo R2 = 0.0537 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | .0505779 .0172932 2.92 0.003 .0166838 .084472 _Igroup_2 | .4060124 .3090247 1.31 0.189 -.1996649 1.01169 _Igroup_3 | -.1536915 .3116762 -0.49 0.622 -.7645655 .4571825 _Igroup_4 | -.5852777 .6205672 -0.94 0.346 -1.801567 .6310117 _Iivhx_2 | -.6477825 .2898193 -2.24 0.025 -1.215818 -.079747 _Iivhx_3 | -.7955052 .2542323 -3.13 0.002 -1.293791 -.2972191 race | .2411928 .2244176 1.07 0.282 -.1986576 .6810432 treat | .4199453 .1996789 2.10 0.035 .0285818 .8113087 site | .1618909 .2206026 0.73 0.463 -.2704822 .594264 _cons | -2.660089 .6059571 -4.39 0.000 -3.847743 -1.472435 ------------------------------------------------------------------------------
Figure 4.5, page 111.
preserve clear input midpt coeff 0 0 1.5 .406 9 -.154 28 -.585 end graph twoway scatter coeff midpt, yline(0) connect(l) xlabel(0 1 2 5(5)20 28)
restore
Figure 4.6, page 112.
Note that although the book describes generating ndrgfp1 and ndrgfp2 as below, it appears that for the tables, they were also centered as in ndrgfp1alt and ndrgfp2alt. Thanks to Silvano Andorno for pointing this out.
generate ndrgfp1 = ((ndrugtx + 1) / 10)^(-1) generate ndrgfp2 = ndrgfp1 * ln((ndrugtx + 1) / 10) generate ndrgfp1alt = ((ndrugtx + 1) / 10)^(-1) - 1.804204581 generate ndrgfp2alt = ((ndrugtx + 1) / 10)^(-1) * ln((ndrugtx + 1) / 10) + 1.064696882 generate lgtfp = -4.314 + 0.981*ndrgfp1 + 0.361*ndrgfp2 summarize lgtfp global mlgfp = r(mean) summarize low global mlow = r(mean) generate lgtfp1 = lgtfp + ($mlow-$mlgfp) twoway (line low ndrugtx)(line lgtfp1 ndrugtx), ylabel(-2.184 -.547) xlabel(0 1 2 5(5)40)
Table 4.7, page 113.
Matching the transformations shown in the book, but not the table:
logit dfree age ndrgfp1 ndrgfp2 ivhx2 ivhx3 race treat site Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -307.22312 Iteration 2: log likelihood = -306.72663 Iteration 3: log likelihood = -306.72558 Logit estimates Number of obs = 575 LR chi2(8) = 40.28 Prob > chi2 = 0.0000 Log likelihood = -306.72558 Pseudo R2 = 0.0616 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | .0544455 .0174877 3.11 0.002 .0201703 .0887208 ndrgfp1 | .9814532 .2888474 3.40 0.001 .4153227 1.547584 ndrgfp2 | .3611252 .1098589 3.29 0.001 .1458057 .5764446 ivhx2 | -.6088269 .2911064 -2.09 0.036 -1.179385 -.0382689 ivhx3 | -.7238122 .2555643 -2.83 0.005 -1.224709 -.2229154 race | .2477026 .2242152 1.10 0.269 -.1917512 .6871564 treat | .4223666 .200365 2.11 0.035 .0296584 .8150748 site | .1732142 .2209758 0.78 0.433 -.2598905 .6063189 _cons | -4.313812 .7924526 -5.44 0.000 -5.866991 -2.760634 ------------------------------------------------------------------------------
Matching the table, but not the transformations shown in the book
logit dfree age ndrgfp1alt ndrgfp2alt ivhx2 ivhx3 race treat site Logistic regression Number of obs = 575 LR chi2(8) = 40.28 Prob > chi2 = 0.0000 Log likelihood = -306.72558 Pseudo R2 = 0.0616 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | .0544455 .0174877 3.11 0.002 .0201702 .0887208 ndrgfp1alt | .9814526 .2888486 3.40 0.001 .4153197 1.547585 ndrgfp2alt | .3611249 .1098593 3.29 0.001 .1458046 .5764451 ivhx2 | -.6088269 .2911069 -2.09 0.036 -1.179386 -.0382679 ivhx3 | -.7238122 .2555649 -2.83 0.005 -1.22471 -.2229142 race | .2477026 .2242156 1.10 0.269 -.1917519 .6871572 treat | .4223666 .2003655 2.11 0.035 .0296574 .8150759 site | .1732142 .2209763 0.78 0.433 -.2598915 .6063198 _cons | -2.927559 .5866548 -4.99 0.000 -4.077381 -1.777736 ------------------------------------------------------------------------------
Table 4.9, page 115.
gen agendrgfp1 = age*ndrgfp1 gen racesite = race*site logit dfree age ndrgfp1 ndrgfp2 ivhx2 ivhx3 race treat site agendrgfp1 racesite Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -300.06724 Iteration 2: log likelihood = -298.98837 Iteration 3: log likelihood = -298.98146 Iteration 4: log likelihood = -298.98146 Logit estimates Number of obs = 575 LR chi2(10) = 55.77 Prob > chi2 = 0.0000 Log likelihood = -298.98146 Pseudo R2 = 0.0853 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- age | .1166385 .0288749 4.04 0.000 .0600446 .1732323 ndrgfp1 | 1.669035 .407152 4.10 0.000 .871032 2.467038 ndrgfp2 | .4336886 .1169052 3.71 0.000 .2045586 .6628185 ivhx2 | -.6346307 .2987192 -2.12 0.034 -1.220109 -.0491518 ivhx3 | -.7049475 .2615805 -2.69 0.007 -1.217636 -.1922591 race | .6841068 .2641355 2.59 0.010 .1664107 1.201803 treat | .4349255 .2037596 2.13 0.033 .035564 .834287 site | .516201 .2548881 2.03 0.043 .0166295 1.015773 agendrgfp1 | -.0152697 .0060268 -2.53 0.011 -.0270819 -.0034575 racesite | -1.429457 .5297806 -2.70 0.007 -2.467808 -.3911062 _cons | -6.843864 1.219316 -5.61 0.000 -9.23368 -4.454048 ------------------------------------------------------------------------------
Table 4.11, page 123.
NOTE: G is calculated ‘by hand’ instead of using lrtest because it follows the book.
NOTE: The following code gives the log likelihood and the values for method 1.
logit dfree Iteration 0: log likelihood = -326.86446 Logit estimates Number of obs = 575 LR chi2(0) = -0.00 Prob > chi2 = . Log likelihood = -326.86446 Pseudo R2 = -0.0000 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | -1.068691 .095599 -11.18 0.000 -1.256061 -.88132 ------------------------------------------------------------------------------ logit dfree ndrugtx Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -321.33296 Iteration 2: log likelihood = -320.94874 Iteration 3: log likelihood = -320.94485 Iteration 4: log likelihood = -320.94485 Logit estimates Number of obs = 575 LR chi2(1) = 11.84 Prob > chi2 = 0.0006 Log likelihood = -320.94485 Pseudo R2 = 0.0181 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ndrugtx | -.0749582 .024681 -3.04 0.002 -.123332 -.0265844 _cons | -.7677805 .130326 -5.89 0.000 -1.023215 -.5123462 ------------------------------------------------------------------------------ display -2*(-326.864-(-320.945)) 11.838 logit dfree ndrugtx treat Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -318.82274 Iteration 2: log likelihood = -318.43381 Iteration 3: log likelihood = -318.42996 Iteration 4: log likelihood = -318.42995 Logit estimates Number of obs = 575 LR chi2(2) = 16.87 Prob > chi2 = 0.0002 Log likelihood = -318.42995 Pseudo R2 = 0.0258 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ndrugtx | -.0739215 .0244703 -3.02 0.003 -.1218825 -.0259606 treat | .4347941 .1947802 2.23 0.026 .053032 .8165562 _cons | -.9990724 .1690772 -5.91 0.000 -1.330458 -.6676872 ------------------------------------------------------------------------------ display -2*(-320.945-(-318.430)) 5.03 logit dfree ndrugtx treat ivhx2 ivhx3 Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -315.36442 Iteration 2: log likelihood = -315.02739 Iteration 3: log likelihood = -315.02524 Iteration 4: log likelihood = -315.02524 Logit estimates Number of obs = 575 LR chi2(4) = 23.68 Prob > chi2 = 0.0001 Log likelihood = -315.02524 Pseudo R2 = 0.0362 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ndrugtx | -.054248 .0246134 -2.20 0.028 -.1024895 -.0060066 treat | .4215337 .1965232 2.14 0.032 .0363553 .8067121 ivhx2 | -.4023913 .2710537 -1.48 0.138 -.9336468 .1288642 ivhx3 | -.5803755 .2289185 -2.54 0.011 -1.029047 -.1317036 _cons | -.7713421 .1877567 -4.11 0.000 -1.139339 -.4033457 ------------------------------------------------------------------------------ display -2*(-318.430-(-315.025)) 6.81 logit dfree ndrugtx treat ivhx2 ivhx3 age Iteration 0: log likelihood = -326.86446 Iteration 1: log likelihood = -310.84391 Iteration 2: log likelihood = -310.29824 Iteration 3: log likelihood = -310.29344 Iteration 4: log likelihood = -310.29344 Logit estimates Number of obs = 575 LR chi2(5) = 33.14 Prob > chi2 = 0.0000 Log likelihood = -310.29344 Pseudo R2 = 0.0507 ------------------------------------------------------------------------------ dfree | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- ndrugtx | -.0637598 .0256279 -2.49 0.013 -.1139896 -.01353 treat | .4513352 .1985966 2.27 0.023 .0620929 .8405774 ivhx2 | -.6236554 .2847028 -2.19 0.028 -1.181663 -.0656482 ivhx3 | -.8056123 .2445359 -3.29 0.001 -1.284894 -.3263307 age | .0525934 .0172105 3.06 0.002 .0188614 .0863254 _cons | -2.332764 .5483861 -4.25 0.000 -3.407581 -1.257947 ------------------------------------------------------------------------------ display -2*(-315.025-(-310.293)) 9.464
NOTE: The following code gives the values for method 2.
display -2*(-326.864-(-310.293)) 33.142 display -2*(-320.945-(-310.293)) 21.304 display -2*(-318.430-(-310.293)) 16.274 display -2*(-315.025-(-310.293)) 9.464
Table 4.12, page 126.
NOTE: We could not recreate this table.
Table 4.13, page 127.
NOTE: We could not recreate this table.
Table 4.14, page 133.
quietly logit dfree age beck ivhx2 ivhx3 ndrugtx race treat site lrtest, saving(0) quietly logit dfree age ivhx2 ivhx3 ndrugtx treat lrtest, saving(1) quietly logit dfree age ivhx2 ivhx3 ndrugtx race treat lrtest, saving(2) logit dfree age ivhx2 ivhx3 ndrugtx treat site lrtest, saving(3) quietly logit dfree age beck ivhx2 ivhx3 ndrugtx treat lrtest, saving(4) quietly logit dfree age ivhx3 ndrugtx treat lrtest, saving(5) lrtest, using(0) model(1) Logit: likelihood-ratio test chi2(3) = 1.34 Prob > chi2 = 0.7198 lrtest, using(0) model(2) Logit: likelihood-ratio test chi2(2) = 0.47 Prob > chi2 = 0.7922 lrtest, using(0) model(3) Logit: likelihood-ratio test chi2(2) = 1.01 Prob > chi2 = 0.6021 lrtest, using(0) model(4) Logit: likelihood-ratio test chi2(2) = 1.34 Prob > chi2 = 0.5119 lrtest, using(0) model(5) Logit: likelihood-ratio test chi2(4) = 6.34 Prob > chi2 = 0.1751
Table 4.15, page 134.
NOTE: We were unable to recreate this table.
Table 4.16, page 137.
clear input x y1 y2 y3 cnt 1 1 0 0 7 1 0 1 0 12 1 0 0 1 20 0 1 0 0 13 0 0 1 0 8 end expand cnt (55 observations created) logistic x y1 y2 y3 note: y3~=0 predicts success perfectly y3 dropped and 20 obs not used note: y2 dropped due to collinearity Logit estimates Number of obs = 40 LR chi2(1) = 2.53 Prob > chi2 = 0.1115 Log likelihood = -26.409166 Pseudo R2 = 0.0458 ------------------------------------------------------------------------------ x | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- y1 | .3589744 .2348775 -1.57 0.117 .0995683 1.294213 ------------------------------------------------------------------------------
NOTE: Stata is throwing out y3 and hence the results are different than those shown in the book. The point is that if you do not throw out y3, the odds ratios go to infinity, which is not correct.
Table 4.17, page 137.
clear input z x y cnt 1 1 1 5 1 1 0 5 1 0 1 2 1 0 0 8 2 1 1 10 2 1 0 2 2 0 1 2 2 0 0 6 3 1 1 15 3 0 1 1 3 0 0 4 end expand cnt (49 observations created)
Table 4.18, page 138. Results of fitting logistic regression models to the data in Table 4.17.
xi: logit y x i.z i.z _Iz_1-3 (naturally coded; _Iz_1 omitted) Iteration 0: log likelihood = -40.751596 Iteration 1: log likelihood = -27.598477 Iteration 2: log likelihood = -26.975899 Iteration 3: log likelihood = -26.956186 Iteration 4: log likelihood = -26.956153 Logit estimates Number of obs = 60 LR chi2(3) = 27.59 Prob > chi2 = 0.0000 Log likelihood = -26.956153 Pseudo R2 = 0.3385 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x | 2.768072 .7156901 3.87 0.000 1.365345 4.170799 _Iz_2 | 1.188759 .8118658 1.46 0.143 -.4024691 2.779986 _Iz_3 | 2.038156 .8889852 2.29 0.022 .2957769 3.780535 _cons | -2.318938 .7727629 -3.00 0.003 -3.833526 -.8043506 ------------------------------------------------------------------------------ xi: logit y i.z*x i.z _Iz_1-3 (naturally coded; _Iz_1 omitted) i.z*x _IzXx_# (coded as above) note: _IzXx_3~=0 predicts success perfectly _IzXx_3 dropped and 15 obs not used Iteration 0: log likelihood = -30.913271 Iteration 1: log likelihood = -24.44454 Iteration 2: log likelihood = -24.343321 Iteration 3: log likelihood = -24.342924 Logit estimates Number of obs = 45 LR chi2(4) = 13.14 Prob > chi2 = 0.0106 Log likelihood = -24.342924 Pseudo R2 = 0.2125 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Iz_2 | .2876821 1.136512 0.25 0.800 -1.93984 2.515204 _Iz_3 | -1.36e-16 1.369298 -0.00 1.000 -2.683775 2.683775 x | 1.386294 1.012419 1.37 0.171 -.5980107 3.370599 _IzXx_2 | 1.321756 1.513806 0.87 0.383 -1.64525 4.288762 _cons | -1.386294 .7905647 -1.75 0.080 -2.935773 .163184 ------------------------------------------------------------------------------
NOTE: See bolded output above. _IzXx_3~=0 predicts success perfectly; _IzXx_3 dropped and 15 obs not used. Because of the numerical problem with the empty cell, you need to use logexact or statexact.
Table 4.19, page 139.
clear input x y 1 0 2 0 3 0 4 0 5 0 5.5 0 6 1 7 1 8 1 9 1 10 1 11 1 end logit y x outcome = x>5.5 predicts data perfectly r(2000); replace x = 6 in 6 (1 real change made) logit y x note: outcome = x>6 predicts data perfectly except for x==6 subsample: x dropped and 10 obs not used Iteration 0: log likelihood = -1.3862944 Logit estimates Number of obs = 2 LR chi2(0) = 0.00 Prob > chi2 = . Log likelihood = -1.3862944 Pseudo R2 = 0.0000 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _cons | 0 1.414214 0.00 1.000 -2.771808 2.771808 ------------------------------------------------------------------------------ replace x = 6.05 in 6 (1 real change made) logit y x Iteration 0: log likelihood = -8.3177662 Iteration 1: log likelihood = -3.5936372 Iteration 2: log likelihood = -2.5215663 Iteration 3: log likelihood = -1.9937606 Iteration 4: log likelihood = -1.7141988 Iteration 5: log likelihood = -1.5824089 Iteration 6: log likelihood = -1.5355823 Iteration 7: log likelihood = -1.5250977 Iteration 8: log likelihood = -1.5241422 Iteration 9: log likelihood = -1.5241292 Iteration 10: log likelihood = -1.5241292 Logit estimates Number of obs = 12 LR chi2(1) = 13.59 Prob > chi2 = 0.0002 Log likelihood = -1.5241292 Pseudo R2 = 0.8168 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x | 4.345349 6.088002 0.71 0.475 -7.586917 16.27761 _cons | -26.17541 36.72909 -0.71 0.476 -98.16311 45.81229 ------------------------------------------------------------------------------ note: 1 failure and 1 success completely determined. replace x = 6.1 in 6 (1 real change made) logit y x Iteration 0: log likelihood = -8.3177662 Iteration 1: log likelihood = -3.6113685 Iteration 2: log likelihood = -2.5518515 Iteration 3: log likelihood = -2.0394264 Iteration 4: log likelihood = -1.7788149 Iteration 5: log likelihood = -1.6667265 Iteration 6: log likelihood = -1.6348295 Iteration 7: log likelihood = -1.6306873 Iteration 8: log likelihood = -1.6305766 Iteration 9: log likelihood = -1.6305765 Logit estimates Number of obs = 12 LR chi2(1) = 13.37 Prob > chi2 = 0.0003 Log likelihood = -1.6305765 Pseudo R2 = 0.8040 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x | 3.635619 4.185012 0.87 0.385 -4.566853 11.83809 _cons | -21.97833 25.39863 -0.87 0.387 -71.75874 27.80207 ------------------------------------------------------------------------------ note: 1 failure and 1 success completely determined. replace x = 6.15 in 6 (1 real change made) logit y x Iteration 0: log likelihood = -8.3177662 Iteration 1: log likelihood = -3.6293154 Iteration 2: log likelihood = -2.5826053 Iteration 3: log likelihood = -2.0857308 Iteration 4: log likelihood = -1.8436308 Iteration 5: log likelihood = -1.7490886 Iteration 6: log likelihood = -1.7276365 Iteration 7: log likelihood = -1.7259834 Iteration 8: log likelihood = -1.7259691 Logit estimates Number of obs = 12 LR chi2(1) = 13.18 Prob > chi2 = 0.0003 Log likelihood = -1.7259691 Pseudo R2 = 0.7925 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x | 3.220325 3.331755 0.97 0.334 -3.309796 9.750446 _cons | -19.5306 20.33991 -0.96 0.337 -59.39609 20.33488 ------------------------------------------------------------------------------ replace x = 6.2 in 6 (1 real change made) logit y x Iteration 0: log likelihood = -8.3177662 Iteration 1: log likelihood = -3.6474741 Iteration 2: log likelihood = -2.6138084 Iteration 3: log likelihood = -2.1326014 Iteration 4: log likelihood = -1.9084543 Iteration 5: log likelihood = -1.8293235 Iteration 6: log likelihood = -1.815043 Iteration 7: log likelihood = -1.8143783 Iteration 8: log likelihood = -1.8143764 Logit estimates Number of obs = 12 LR chi2(1) = 13.01 Prob > chi2 = 0.0003 Log likelihood = -1.8143764 Pseudo R2 = 0.7819 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x | 2.926873 2.817514 1.04 0.299 -2.595353 8.449099 _cons | -17.80292 17.29827 -1.03 0.303 -51.70691 16.10107 ------------------------------------------------------------------------------ replace x = 8 in 6 (1 real change made) logit y x Iteration 0: log likelihood = -8.3177662 Iteration 1: log likelihood = -4.4070996 Iteration 2: log likelihood = -3.8715929 Iteration 3: log likelihood = -3.7841346 Iteration 4: log likelihood = -3.7799185 Iteration 5: log likelihood = -3.7799047 Logit estimates Number of obs = 12 LR chi2(1) = 9.08 Prob > chi2 = 0.0026 Log likelihood = -3.7799047 Pseudo R2 = 0.5456 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x | .9664819 .5311971 1.82 0.069 -.0746452 2.007609 _cons | -6.123959 3.585271 -1.71 0.088 -13.15096 .9030426 ------------------------------------------------------------------------------
Table 4.20, page 140.
clear input subj x1 x2 x3 y 1 .225 .231 1.026 0 2 .487 .489 1.022 1 3 -1.080 -1.070 1.074 0 4 -.87 -.87 1.091 0 5 -.58 -.57 1.095 0 6 -.64 -.64 1.01 0 7 1.614 1.619 1.087 0 8 .352 .355 1.095 1 9 -1.025 -1.018 1.008 0 10 .929 .937 1.057 1 end list subj x1 x2 x3 y subj x1 x2 x3 y 1. 1 .225 .231 1.026 0 2. 2 .487 .489 1.022 1 3. 3 -1.08 -1.07 1.074 0 4. 4 -.87 -.87 1.091 0 5. 5 -.58 -.57 1.095 0 6. 6 -.64 -.64 1.01 0 7. 7 1.614 1.619 1.087 0 8. 8 .352 .355 1.095 1 9. 9 -1.025 -1.018 1.008 0 10. 10 .929 .937 1.057 1
Table 4.21, page 141.
Column 2
logit y x1 Iteration 0: log likelihood = -6.108643 Iteration 1: log likelihood = -4.9146936 Iteration 2: log likelihood = -4.8717399 Iteration 3: log likelihood = -4.8713285 Iteration 4: log likelihood = -4.8713284 Logit estimates Number of obs = 10 LR chi2(1) = 2.47 Prob > chi2 = 0.1157 Log likelihood = -4.8713284 Pseudo R2 = 0.2026 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | 1.380311 1.005368 1.37 0.170 -.5901735 3.350795 _cons | -1.001712 .8294342 -1.21 0.227 -2.627373 .6239494 ------------------------------------------------------------------------------
Column 3 (Note that there is likely a typo in this column.)
logit y x1 x2 Iteration 0: log likelihood = -6.108643 Iteration 1: log likelihood = -4.8196088 Iteration 2: log likelihood = -4.7259858 Iteration 3: log likelihood = -4.7212724 Iteration 4: log likelihood = -4.721251 Logit estimates Number of obs = 10 LR chi2(2) = 2.77 Prob > chi2 = 0.2497 Log likelihood = -4.721251 Pseudo R2 = 0.2271 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | 146.395 276.9998 0.53 0.597 -396.5147 689.3047 x2 | -144.9098 276.6344 -0.52 0.600 -687.1033 397.2836 _cons | -.3703049 1.362457 -0.27 0.786 -3.040672 2.300062 ------------------------------------------------------------------------------
Column 4 (Note that there is likely a typo in this column.)
logit y x3 Iteration 0: log likelihood = -6.108643 Iteration 1: log likelihood = -6.104626 Iteration 2: log likelihood = -6.1046254 Logit estimates Number of obs = 10 LR chi2(1) = 0.01 Prob > chi2 = 0.9286 Log likelihood = -6.1046254 Pseudo R2 = 0.0007 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x3 | 1.787782 19.97092 0.09 0.929 -37.35449 40.93006 _cons | -2.736861 21.12781 -0.13 0.897 -44.1466 38.67288 ------------------------------------------------------------------------------
Column 5
logit y x1 x2 x3 Iteration 0: log likelihood = -6.108643 Iteration 1: log likelihood = -4.8146158 Iteration 2: log likelihood = -4.7162391 Iteration 3: log likelihood = -4.71065 Iteration 4: log likelihood = -4.7106177 Logit estimates Number of obs = 10 LR chi2(3) = 2.80 Prob > chi2 = 0.4242 Log likelihood = -4.7106177 Pseudo R2 = 0.2289 ------------------------------------------------------------------------------ y | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- x1 | 142.9769 282.1838 0.51 0.612 -410.0932 696.047 x2 | -141.4593 281.832 -0.50 0.616 -693.8398 410.9212 x3 | -3.621109 24.95384 -0.15 0.885 -52.52974 45.28752 _cons | 3.42313 26.1558 0.13 0.896 -47.8413 54.68756 ------------------------------------------------------------------------------