The first examples in this chapter makes use of the chdagea file.
use chdage
Table 3.2 -- page 42
/* create dichotomous variable for age */
generate aged = (age>=55)
tabulate chd aged
| aged
chd | 0 1 | Total
-----------+----------------------+----------
0 | 51 6 | 57
1 | 22 21 | 43
-----------+----------------------+----------
Total | 73 27 | 100
Table 3.3 -- page 43
logit chd aged
Iteration 0: log likelihood = -68.331491
Iteration 1: log likelihood = -59.020453
Iteration 2: log likelihood = -58.979594
Iteration 3: log likelihood = -58.979565
Logit estimates Number of obs = 100
LR chi2(1) = 18.70
Prob > chi2 = 0.0000
Log likelihood = -58.979565 Pseudo R2 = 0.1369
------------------------------------------------------------------------------
chd | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
aged | 2.093546 .5285335 3.961 0.000 1.057639 3.129453
_cons | -.8407832 .2550733 -3.296 0.001 -1.340718 -.3408487
------------------------------------------------------------------------------
logit chd aged, or
Logit estimates Number of obs = 100
LR chi2(1) = 18.70
Prob > chi2 = 0.0000
Log likelihood = -58.979565 Pseudo R2 = 0.1369
------------------------------------------------------------------------------
chd | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
aged | 8.113636 4.288329 3.961 0.000 2.879566 22.86147
------------------------------------------------------------------------------
Table 3.10 -- page 54
/* create 4 a category variable for age */
generate agecat=recode(age,34,44,54,69)
recode agecat 34=1 44=2 54=3 69=4
tabulate chd agecat
| agecat
chd | 1 2 3 4 | Total
-----------+--------------------------------------------+----------
0 | 22 19 10 6 | 57
1 | 3 8 11 21 | 43
-----------+--------------------------------------------+----------
Total | 25 27 21 27 | 100
Table 3.11 -- page 55
/* create orthogonal polynomials for agecat */
generate d1 = .
replace d1=-.6708 if agecat==1
replace d1=-.2236 if agecat==2
replace d1=.2236 if agecat==3
replace d1=.6708 if agecat==4
generate d2=.
replace d2=.5 if agecat==1 | agecat==4
replace d2=-.5 if agecat==2 | agecat==3
generate d3 = .
replace d3=-.2236 if agecat==1
replace d3=.6708 if agecat==2
replace d3=-.6708 if agecat==3
replace d3=.2236 if agecat==4
table agecat,c(mean d1 mean d2 mean d3)
----------+-----------------------------------
agecat | mean(d1) mean(d2) mean(d3)
----------+-----------------------------------
1 | -.6708 .5 -.2236
2 | -.2236 -.5 .6708
3 | .2236 -.5 -.6708
4 | .6708 .5 .2236
----------+-----------------------------------
Table 3.12 -- page 55
logit chd d1 d2 d3
Iteration 0: log likelihood = -68.331491
Iteration 1: log likelihood = -54.744608
Iteration 2: log likelihood = -54.420347
Iteration 3: log likelihood = -54.41519
Iteration 4: log likelihood = -54.415187
Logit estimates Number of obs = 100
LR chi2(3) = 27.83
Prob > chi2 = 0.0000
Log likelihood = -54.415187 Pseudo R2 = 0.2037
------------------------------------------------------------------------------
chd | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
d1 | 2.391746 .5341605 4.478 0.000 1.344811 3.438681
d2 | .01501 .4903096 0.031 0.976 -.9459791 .9759992
d3 | .0814558 .4421639 0.184 0.854 -.7851694 .9480811
_cons | -.3773386 .2451548 -1.539 0.124 -.8578332 .103156
------------------------------------------------------------------------------
The next example makes use of the lowbwt.dta file.
use lowbwt
Table 3.17 -- page 70 (edited for length)
/* create dichotomous variable for lwt */
generate lwd = (lwt<110)
/* create interaction variable for lwd and age */
generate lwdage = lwd*age
logit low
Logit estimates Number of obs = 189
LR chi2(0) = 0.00
Prob > chi2 = .
Log likelihood = -117.336 Pseudo R2 = 0.0000
------------------------------------------------------------------------------
low | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
_cons | -.789997 .156976 -5.033 0.000 -1.097664 -.4823297
------------------------------------------------------------------------------
logit low lwd
Logit estimates Number of obs = 189
LR chi2(1) = 8.43
Prob > chi2 = 0.0037
Log likelihood = -113.12058 Pseudo R2 = 0.0359
------------------------------------------------------------------------------
low | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
lwd | 1.053762 .3615635 2.914 0.004 .3451102 1.762413
_cons | -1.053762 .1883882 -5.594 0.000 -1.422996 -.6845277
------------------------------------------------------------------------------
logit low lwd age
Logit estimates Number of obs = 189
LR chi2(2) = 10.39
Prob > chi2 = 0.0056
Log likelihood = -112.14338 Pseudo R2 = 0.0443
------------------------------------------------------------------------------
low | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
lwd | 1.010122 .3642627 2.773 0.006 .2961806 1.724064
age | -.044232 .0322248 -1.373 0.170 -.1073913 .0189274
_cons | -.026891 .7621481 -0.035 0.972 -1.520674 1.466892
------------------------------------------------------------------------------
logit low lwd age lwdage
Logit estimates Number of obs = 189
LR chi2(3) = 13.53
Prob > chi2 = 0.0036
Log likelihood = -110.56997 Pseudo R2 = 0.0577
------------------------------------------------------------------------------
low | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
lwd | -1.944089 1.724804 -1.127 0.260 -5.324643 1.436465
age | -.0795722 .0396343 -2.008 0.045 -.157254 -.0018904
lwdage | .1321967 .0756982 1.746 0.081 -.0161691 .2805626
_cons | .7744952 .9100949 0.851 0.395 -1.009258 2.558248
------------------------------------------------------------------------------
Table 3.18 -- page 70
* Stata 8 code.
vce
* Stata 9 code and output.
estat vce
Covariance matrix of coefficients of logit model
e(V) | lwd age lwdage _cons
-------------+------------------------------------------------
lwd | 2.974949
age | .03526621 .00157088
lwdage | -.12760349 -.00157088 .00573022
_cons | -.82827277 -.03526621 .03526621 .82827277
Table 3.20 -- page 72
tabulate low smoke
| smoke
< 2500g | 0 1 | Total
-----------+----------------------+----------
0 | 86 44 | 130
1 | 29 30 | 59
-----------+----------------------+----------
Total | 115 74 | 189
Table 3.21 -- page 72
sort race
by race: tabulate low smoke
-> race= white
| smoke
< 2500g | 0 1 | Total
-----------+----------------------+----------
0 | 40 33 | 73
1 | 4 19 | 23
-----------+----------------------+----------
Total | 44 52 | 96
-> race= black
| smoke
< 2500g | 0 1 | Total
-----------+----------------------+----------
0 | 11 4 | 15
1 | 5 6 | 11
-----------+----------------------+----------
Total | 16 10 | 26
-> race= other
| smoke
< 2500g | 0 1 | Total
-----------+----------------------+----------
0 | 35 7 | 42
1 | 20 5 | 25
-----------+----------------------+----------
Total | 55 12 | 67
Table 3.21 -- page 75 (edited for length)
Focus is on log likelihood values, likelihood ratio tests and coefficients for smoke
/* create dummy variables for race */
xi i.race
/* create interaction variables for race by smoke */
generate rsmoke2= Irace_2*smoke
generate rsmoke3= Irace_3*smoke
logit low smoke Irace_2 Irace_3 rsmoke2 rsmoke3
Logit estimates Number of obs = 189
LR chi2(5) = 17.85
Prob > chi2 = 0.0031
Log likelihood = -108.40889 Pseudo R2 = 0.0761
------------------------------------------------------------------------------
low | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
smoke | 1.750517 .5982759 2.926 0.003 .5779173 2.923116
Irace_2 | 1.514128 .7522689 2.013 0.044 .0397077 2.988548
Irace_3 | 1.742969 .5946183 2.931 0.003 .5775389 2.9084
rsmoke2 | -.556594 1.032235 -0.539 0.590 -2.579738 1.46655
rsmoke3 | -1.527373 .8828152 -1.730 0.084 -3.257659 .202913
_cons | -2.302585 .5244039 -4.391 0.000 -3.330398 -1.274772
------------------------------------------------------------------------------
lrtest,saving(0)
logit low smoke Irace_2 Irace_3
Logit estimates Number of obs = 189
LR chi2(3) = 14.70
Prob > chi2 = 0.0021
Log likelihood = -109.98736 Pseudo R2 = 0.0626
------------------------------------------------------------------------------
low | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
smoke | 1.116004 .3692258 3.023 0.003 .3923346 1.839673
Irace_2 | 1.084088 .4899845 2.212 0.027 .1237362 2.04444
Irace_3 | 1.108563 .4003054 2.769 0.006 .3239787 1.893147
_cons | -1.840539 .3528633 -5.216 0.000 -2.532138 -1.148939
------------------------------------------------------------------------------
lrtest
Logit: likelihood-ratio test chi2(2) = 3.16
Prob > chi2 = 0.2063
lrtest, saving(1)
logit low smoke
Logit estimates Number of obs = 189
LR chi2(1) = 4.87
Prob > chi2 = 0.0274
Log likelihood = -114.9023 Pseudo R2 = 0.0207
------------------------------------------------------------------------------
low | Coef. Std. Err. z P>|z| [95% Conf. Interval]
---------+--------------------------------------------------------------------
smoke | .7040592 .3196386 2.203 0.028 .0775791 1.330539
_cons | -1.087051 .2147299 -5.062 0.000 -1.507914 -.6661886
------------------------------------------------------------------------------
lrtest, using(1)
Logit: likelihood-ratio test chi2(2) = 9.83
Prob > chi2 = 0.0073
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.