
Four Possibilities
regress write read [output omitted] predict p1 graph write p1 read, s(oi) c(.L) sort /* stata 7 */ scatter write p1 read, msym(o i) con(. L) sort /* stata 8 */![]()
regress write read female [output omitted] predict p2 sort female p2 graph write p2 read, s(oi) c(.L) /* stata 7 */ scatter write p2 read, msym(o i) con(. L) sort /* stata 8 */![]()
generate fxr = female*read regress write read female fxr [output omitted] predict p3 sort female p3 graph write p3 read, s(oi) c(.L) sort /* stata 7 */ scatter write p3 read, msym(o i) con(. L) sort /* stata 8 */![]()
Classical ANCOVA
Assumptions

Selecting a Covariate
Logic of ANCOVA

Which may be rewritten:

Homogeneity of Regression

Steps in ANCOVA
Numerical Example: coded using Effect Coding
input id y c1 c2 grp v1 v2 v3
1 6 1 6 1 1 0 0
2 9 1 7 1 1 0 0
3 8 2 15 1 1 0 0
4 8 3 13 1 1 0 0
5 12 3 18 1 1 0 0
6 12 4 9 1 1 0 0
7 10 4 16 1 1 0 0
8 8 5 10 1 1 0 0
9 12 5 16 1 1 0 0
10 13 6 18 1 1 0 0
11 13 4 12 2 0 1 0
12 16 4 12 2 0 1 0
13 15 5 17 2 0 1 0
14 16 6 9 2 0 1 0
15 19 6 20 2 0 1 0
16 17 8 18 2 0 1 0
17 19 8 16 2 0 1 0
18 23 9 20 2 0 1 0
19 19 10 10 2 0 1 0
20 22 10 17 2 0 1 0
21 20 7 8 3 0 0 1
22 22 7 14 3 0 0 1
23 24 9 11 3 0 0 1
24 26 9 11 3 0 0 1
25 24 10 16 3 0 0 1
26 25 11 20 3 0 0 1
27 28 11 19 3 0 0 1
28 27 12 19 3 0 0 1
29 29 13 12 3 0 0 1
30 26 13 16 3 0 0 1
31 27 7 16 4 -1 -1 -1
32 28 8 10 4 -1 -1 -1
33 25 8 13 4 -1 -1 -1
34 27 9 7 4 -1 -1 -1
35 31 9 15 4 -1 -1 -1
36 29 10 20 4 -1 -1 -1
37 32 10 16 4 -1 -1 -1
38 30 12 21 4 -1 -1 -1
39 32 12 15 4 -1 -1 -1
40 33 14 21 4 -1 -1 -1
end
/* compute interaction terms */
generate c1v1 = c1 * v1
generate c1v2 = c1 * v2
generate c1v3 = c1 * v3
/* run regression */
regress y c1 v1 v2 v3 c1v1 c1v2 c1v3
Source | SS df MS Number of obs = 40
---------+------------------------------ F( 7, 32) = 109.27
Model | 2382.23359 7 340.319084 Prob > F = 0.0000
Residual | 99.6664092 32 3.11457529 R-squared = 0.9598
---------+------------------------------ Adj R-squared = 0.9511
Total | 2481.90 39 63.6384615 Root MSE = 1.7648
------------------------------------------------------------------------------
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---------+--------------------------------------------------------------------
c1 | .9994664 .1429378 6.992 0.000 .7083116 1.290621
v1 | -6.107133 1.452131 -4.206 0.000 -9.065026 -3.14924
v2 | -2.671148 1.736811 -1.538 0.134 -6.208916 .8666195
v3 | 1.54334 2.267783 0.681 0.501 -3.075983 6.162663
c1v1 | -.0979512 .2818144 -0.348 0.730 -.6719884 .476086
c1v2 | .1047003 .229945 0.455 0.652 -.3636823 .5730829
c1v3 | .0509923 .2369574 0.215 0.831 -.4316741 .5336588
_cons | 12.84198 1.127409 11.391 0.000 10.54552 15.13844
------------------------------------------------------------------------------
/* test homogeneity of regression slopes */
test c1v1 c1v2 c1v2
( 1) c1v1 = 0.0
( 2) c1v2 = 0.0
( 3) c1v3 = 0.0
F( 3, 32) = 0.11
Prob > F = 0.9550
/* run regression again */
regress y c1 v1 v2 v3
Source | SS df MS Number of obs = 40
---------+------------------------------ F( 4, 35) = 206.97
Model | 2381.22741 4 595.306852 Prob > F = 0.0000
Residual | 100.672592 35 2.87635976 R-squared = 0.9594
---------+------------------------------ Adj R-squared = 0.9548
Total | 2481.90 39 63.6384615 Root MSE = 1.696
------------------------------------------------------------------------------
y | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---------+--------------------------------------------------------------------
c1 | 1.013052 .1337037 7.577 0.000 .7416185 1.284485
v1 | -6.469857 .7313256 -8.847 0.000 -7.954527 -4.985187
v2 | -2.016843 .4719217 -4.274 0.000 -2.974895 -1.058791
v3 | 1.941392 .5781528 3.358 0.002 .7676797 3.115105
_cons | 12.82548 1.054168 12.166 0.000 10.68541 14.96556
------------------------------------------------------------------------------
/* test treatment */
test v1 v2 v3
( 1) v1 = 0.0
( 2) v2 = 0.0
( 3) v3 = 0.0
F( 3, 35) = 48.19
Prob > F = 0.0000
/* test covariate (redundant) */
test c1
( 1) c1 = 0.0
F( 1, 35) = 57.41
Prob > F = 0.0000
/* compute original means */
table grp, contents(mean y)
----------+-----------
grp | mean(y)
----------+-----------
1 | 9.8
2 | 17.9
3 | 25.1
4 | 29.4
----------+-----------
/* compute adjusted means */
adjust c1, by(grp) generate(adjmeans)
-------------------------------------------------------------------------------
Dependent variable: y Command: regress
Created variable: adjmeans
Variables left as is: v1, v2, v3
Covariate set to mean: c1 = 7.625
-------------------------------------------------------------------------------
----------+-----------
grp | xb
----------+-----------
1 | 14.0801
2 | 18.5332
3 | 22.4914
4 | 27.0953
----------+-----------
Key: xb = Linear Prediction
Regression Equation

Separate Intercepts

Computing Adjusted Means

Phil Ender, 22Feb00