Some general comments. Because many of the examples in this chapter are computed from summary statistics we will be making extensive use of Stata’s immediate commands. Each of these commands ends with the letter “i.”
Section 7.1 uses large sample z-tests. Stata reports the small sample t-tests. For this example the results will be slightly different. The t-test results are acceptable in place of z-tests because they are more conservative.
Two-sample confidence interval for means, page 214; two-sample test comparing means, page 215.
ttesti 6764 32.6 18.2 4252 18.1 12.9 Two-sample t test with equal variances ------------------------------------------------------------------------------ | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | 6764 32.6 .221294 18.2 32.16619 33.03381 y | 4252 18.1 .1978304 12.9 17.71215 18.48785 ---------+-------------------------------------------------------------------- combined | 11016 27.00323 .1697512 17.8166 26.67049 27.33597 ---------+-------------------------------------------------------------------- diff | 14.5 .3201652 13.87242 15.12758 <- confidence interval ------------------------------------------------------------------------------ Degrees of freedom: 11014 Ho: mean(x) - mean(y) = diff = 0 Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0 t = 45.2891 t = 45.2891 t = 45.2891 P < t = 1.0000 P > |t| = 0.0000 P > t = 0.0000
Two-sample confidence interval for proportions, page 218; two-sample test comparing proportions, page 220.
prtesti 1900 .14 345 .35 Two-sample test of proportion x: Number of obs = 1900 y: Number of obs = 345 ------------------------------------------------------------------------------ Variable | Mean Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | .14 .0079604 17.587 0.0000 .1243978 .1556022 y | .35 .0256792 13.6297 0.0000 .2996697 .4003303 ---------+-------------------------------------------------------------------- diff | -.21 .0268847 -.2626931 -.1573069 <- confidence interval | under Ho: .022099 -9.50269 0.0000 ------------------------------------------------------------------------------ Ho: proportion(x) - proportion(y) = diff = 0 Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0 z = -9.503 z = -9.503 z = -9.503 P < z = 0.0000 P > |z| = 0.0000 P > z = 1.0000
Two-group t-test, page 223.
ttesti 3 20 10 3 40 8.66 Two-sample t test with equal variances ------------------------------------------------------------------------------ | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | 3 20 5.773503 10 -4.841377 44.84138 y | 3 40 4.999853 8.66 18.48737 61.51263 ---------+-------------------------------------------------------------------- combined | 6 30 5.627288 13.78398 15.53459 44.46541 ---------+-------------------------------------------------------------------- diff | -20 7.63753 -41.20518 1.205183 ------------------------------------------------------------------------------ Degrees of freedom: 4 Ho: mean(x) - mean(y) = diff = 0 Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0 t = -2.6186 t = -2.6186 t = -2.6186 P < t = 0.0294 P > |t| = 0.0589 P > t = 0.9706 ttesti 3 20 10 3 40 8.66, unequal Two-sample t test with unequal variances ------------------------------------------------------------------------------ | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | 3 20 5.773503 10 -4.841377 44.84138 y | 3 40 4.999853 8.66 18.48737 61.51263 ---------+-------------------------------------------------------------------- combined | 6 30 5.627288 13.78398 15.53459 44.46541 ---------+-------------------------------------------------------------------- diff | -20 7.63753 -41.37702 1.377019 ------------------------------------------------------------------------------ Satterthwaite's degrees of freedom: 3.91997 Ho: mean(x) - mean(y) = diff = 0 Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0 t = -2.6186 t = -2.6186 t = -2.6186 P < t = 0.0301 P > |t| = 0.0601 P > t = 0.9699
Table 7.3, page 224.
ttesti 3 20 10 3 40 8.66 Two-sample t test with equal variances ------------------------------------------------------------------------------ | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | 3 20 5.773503 10 -4.841377 44.84138 y | 3 40 4.999853 8.66 18.48737 61.51263 ---------+-------------------------------------------------------------------- combined | 6 30 5.627288 13.78398 15.53459 44.46541 ---------+-------------------------------------------------------------------- diff | -20 7.63753 -41.20518 1.205183 ------------------------------------------------------------------------------ Degrees of freedom: 4 Ho: mean(x) - mean(y) = diff = 0 Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0 t = -2.6186 t = -2.6186 t = -2.6186 P < t = 0.0294 P > |t| = 0.0589 P > t = 0.9706 ttesti 3 20 10 3 40 8.66, unequal Two-sample t test with unequal variances ------------------------------------------------------------------------------ | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | 3 20 5.773503 10 -4.841377 44.84138 y | 3 40 4.999853 8.66 18.48737 61.51263 ---------+-------------------------------------------------------------------- combined | 6 30 5.627288 13.78398 15.53459 44.46541 ---------+-------------------------------------------------------------------- diff | -20 7.63753 -41.37702 1.377019 ------------------------------------------------------------------------------ Satterthwaite's degrees of freedom: 3.91997 Ho: mean(x) - mean(y) = diff = 0 Ha: diff < 0 Ha: diff ~= 0 Ha: diff > 0 t = -2.6186 t = -2.6186 t = -2.6186 P < t = 0.0301 P > |t| = 0.0601 P > t = 0.9699
Table 7.4, page 225.
input mother idenity freq 1 1 2 1 2 23 2 1 0 2 2 20 end tabulate mother idenity [fw=freq], exact | idenity mother | 1 2 | Total -----------+----------------------+---------- 1 | 2 23 | 25 2 | 0 20 | 20 -----------+----------------------+---------- Total | 2 43 | 45 Fisher's exact = 0.495 1-sided Fisher's exact = 0.303
Table 7.6, page 229.
ttesti 3 -20 5 0 One-sample t test ------------------------------------------------------------------------------ | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval] ---------+-------------------------------------------------------------------- x | 3 -20 2.886751 5 -32.42069 -7.579311 ------------------------------------------------------------------------------ Degrees of freedom: 2 Ho: mean(x) = 0 Ha: mean < 0 Ha: mean ~= 0 Ha: mean > 0 t = -6.9282 t = -6.9282 t = -6.9282 P < t = 0.0101 P > |t| = 0.0202 P > t = 0.9899
McNemar’s test, page 231. Agresti and Finley reports McNemar’s test as a z-test while Stata reports it as a chi-square. With 1 degree of freedom chi-square equals z-squared.
mcci 292 25 14 9 | Controls | Cases | Exposed Unexposed | Total -----------------+------------------------+---------- Exposed | 292 25 | 317 Unexposed | 14 9 | 23 -----------------+------------------------+---------- Total | 306 34 | 340 McNemar's chi2(1) = 3.10 Prob > chi2 = 0.0782 Exact McNemar significance probability = 0.1081 Proportion with factor Cases .9323529 Controls .9 [95% Conf. Interval] --------- -------------------- difference .0323529 -.0064235 .0711294 ratio 1.035948 .9960248 1.077471 rel. diff. .3235294 .0274379 .6196209 odds ratio 1.785714 .8931865 3.715968 (exact) display 1.76^2 3.0976