I'd like to get a matrix showing all possible contrasts for a given factor variable after a regression. For example, let's say I have a factor variable with 4 levels.
I know I can use contrasts r.region, contrast a.region, or contrast ar.region, to get the default, adjacent, or reverse adjacent contrasts, respectively. The r(table) matrix that's accessible after doing any one of these is half way to what I need.
I'd like a single matrix like this one but with all possible contrasts, regardless of whether they are shown in the original results. That would be either 3 additional columns if 2vs1 and 1vs2, etc., are regarded as redundant (just sign differences, ultimately), or 9 if they are not. I would have a slight preference for the latter, but either would be great. How might I get such a matrix? Thank you.
Code:
sysuse census.data, clear
tab region
Census |
region | Freq. Percent Cum.
------------+-----------------------------------
NE | 9 18.00 18.00
N Cntrl | 12 24.00 42.00
South | 16 32.00 74.00
West | 13 26.00 100.00
------------+-----------------------------------
Total | 50 100.00
reg medage i.region
Source | SS df MS Number of obs = 50
-------------+------------------------------ F( 3, 46) = 7.56
Model | 46.3961903 3 15.4653968 Prob > F = 0.0003
Residual | 94.1237947 46 2.04616945 R-squared = 0.3302
-------------+------------------------------ Adj R-squared = 0.2865
Total | 140.519985 49 2.8677548 Root MSE = 1.4304
------------------------------------------------------------------------------
medage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
region |
N Cntrl | -1.708333 .6307664 -2.71 0.009 -2.978 -.4386663
South | -1.614583 .5960182 -2.71 0.009 -2.814306 -.4148606
West | -2.948718 .620282 -4.75 0.000 -4.197281 -1.700155
|
_cons | 31.23333 .4768146 65.50 0.000 30.27356 32.19311
------------------------------------------------------------------------------
Code:
contrast ar.region
Contrasts of marginal linear predictions
Margins : asbalanced
-------------------------------------------------------
| df F P>F
--------------------+----------------------------------
region |
(N Cntrl vs NE) | 1 7.34 0.0095
(South vs N Cntrl) | 1 0.03 0.8645
(West vs South) | 1 6.24 0.0161
Joint | 3 7.56 0.0003
|
Denominator | 46
-------------------------------------------------------
---------------------------------------------------------------------
| Contrast Std. Err. [95% Conf. Interval]
--------------------+------------------------------------------------
region |
(N Cntrl vs NE) | -1.708333 .6307664 -2.978 -.4386663
(South vs N Cntrl) | .0937502 .5462597 -1.005814 1.193314
(West vs South) | -1.334135 .5341191 -2.409261 -.2590085
---------------------------------------------------------------------
matrix list r(table)
r(table)[9,3]
ar2vs1. ar3vs2. ar4vs3.
region region region
b -1.7083332 .09375016 -1.3341345
se .63076642 .54625975 .53411913
t -2.7083452 .17162194 -2.497822
pvalue .00946336 .86448754 .01613433
ll -2.9780002 -1.0058137 -2.4092605
ul -.43866627 1.193314 -.25900847
df 46 46 46
crit 2.0128956 2.0128956 2.0128956
eform 0 0 0

Comment