------------------------------------------------------------------------------- help for xi3 -------------------------------------------------------------------------------Interaction expansion, enhanced
Note: xi3 is not compatible with the following Stata commands: xtmixed, xtmelogit or xtmepoisson.
Caution: xi3 should not be used with pweights, aweights or iweights.The xi3 command is the same as the xi command, except that it allows 3 way interactions, any combination of continuous and categorical variables, and performs additional coding schemes beyond indicator coding, and can create codings that allow for testing simple contrasts and simple effects. It's syntax is much like the xi command.
xi3 [, prefix(string)] term(s)
xi3 [, prefix(string)] : any_stata_command varlist_with_terms ...
where a term is a mixture of continuous (Con) and categorical (Cat) variables of the form:
Main Effects Con varname Cat prefix.varname
Two Way Interactions Cat by Cat prefix.varname1*prefix.varname2 Cat by Con prefix.varname1*varname2 Con by Cat varname1*prefix.varname2 Con by Con varname1*varname2
Three Way Interactions Cat by Cat by Cat prefix.varname1*prefix.varname2*prefix.varname3 Cat by Cat by Con prefix.varname1*prefix.varname2*varname3 ... Con by Con by Con varname1*varname2*varname3
and you can also request simple effects for two way interactions using the @ operator
Cat by Cat prefix.varname1@prefix.varname2 Con by Cat varname1@prefix.varname2
Use of if and in
It is not recommended that you use if or in as part of your command. Instead, use keep or drop prior to using xi3.
Additional Coding Schemes
The xi3 command allows additional prefixes beyond i.varname. These prefixes create a number of additional coding schemes, as described below.
Please note: Starting with version 1.0 (April 7, 2003) the prefixes s, d, and f have been replaced with g, e, and a (respectively). This now permits the s., d. and f. prefixes to be used as time series operators reflecting seasonal differences, backward differencing, and forward differencing (respectively).
i.varname - Indicator (dummy) coding: compares each level to the omitted group c.varname - Centered indicator (dummy) coding g.varname - reference Group coding: compares each level to a reference group e.varname - Effect coding: deviations from the grand mean h.varname - Helmert coding: compares levels of a variable with the mean of subsequent levels r.varname - Reverse Helmert coding: compares levels of a variable with the mean of previous levels a.varname - Adjacent differences: each level vs. the next level b.varname - Backward adjacent differences: each level vs. the previous level o.varname - Orthogonal polynomial contrasts u.varname - User defined coding scheme u.varname - User defined coding scheme
Omitted Categories for Additional Coding Schemes
The refgroup command is included with xi3 to allow you to select the reference group (also called the omitted category). This is simply a shorthand for using char varname[omit] #. The syntax of refgroup is
refgroup varname #
The following describes how omitted categories are handled using each coding scheme.
Indicator coding. The choice of the omitted category works just like the original xi program, i.e. the first category is omitted unless you use char varname[omit] # or char _dta[omit] "prevalent" (see help xi for more information). Note that char _dta[omit] "prevalent" is ignored for all of the other other coding schemes.
Simple and Deviation coding. By default, the first category is the omitted category and you can use char varname[omit] # to choose a different level to be omitted.
Helmert and Forward Difference coding. For these coding schemes the last category is always omitted (because the last category cannot be compared to subsequent categories.
Reverse Helmert and Backward Difference coding. For these coding schemes the first category is always omitted (because the first category cannot be compared to prior categories.
Orthogonal Polynomial coding. The kth level is omitted.
User Defined coding. The user defines k-1 contrasts to be tested, as described in the section Creating User Defined Coding below.
Creating User Defined Coding
It may be easiest to describe user defined coding via an example. Say you have a variable ses with 3 levels, and you wish to form 2 comparisons. The first will compare level 1 with levels 2 and 3, and the second will compare levels 1 and 3. The comparison coefficients for these two comparisons would be.
comparison 1: 1 -.5 -.5 comparison 2: 1 0 -1
You indicate these comparisions like this
. char ses[user] (1 -.5 -.5 1 0 -1)
Simple Comparisons and Simple Effects
Say you wanted to specify adjacent difference contrasts on varname1 at each level of varname2, along with group contrasts on varname2. You can use @ like this to request that coding.
a.varname1@g.varname2
For example to perform adjacent difference conrasts on ses at each level of female and group coding on female, you could type
. xi3 a.ses@s.female
The terms that would be created are listed below along with their interpretation.
_Ises_1 ses(1 vs. 2) _Ises_2 ses(2 vs. 3) _Ifemale_1 female(1 vs. 0) _Ise1Wfe0 ses(1 vs. 2) female==0 _Ise1Wfe1 ses(1 vs. 2) female==1 _Ise2Wfe0 ses(2 vs. 3) female==0 _Ise2Wfe1 ses(2 vs. 3) female==1
As you see, the lower order effects _Ises_1 _Ises_1 and _Ifemale_1 are created as though you had used an interaction. But the terms _Ise1Wfe0 _Ise1Wfe1 _Ise2Wfe0 and _Ise2Wfe1 reflect simple effects of ses at the levels of female. For example _Ise1Wfe0 is the effect of low ses vs. middle ses for males, and _Ise2Wfe0 is the effect of middle ses vs. high ses for males.
If you wanted to form the simple effect of ses for males, you would use the test command to test _Ise1Wfe0 and _Ise2Wfe0, for example
. test _Ise1Wfe0 _Ise2Wfe0
Note that when you use xi3 to create the coding scheme, it creates both the main effects for female and for ses and for the simple contrasts of ses at each level of female. However, if you include all of these terms in an estimation model, it will be overparameterized. Instead, you wish to drop, in this example, the main effect of ses since that effect is also contrained in the simple effects. When you use xi3 with a command, it automatically drops the ses main effects, although those variables are created, see example below.
. xi3 : regress write a.ses@g.female
a.ses _Ises_1-3 (naturally coded; _Ises_3 omitted) g.female _Ifemale_0-1 (naturally coded; _Ifemale_0 omitted)
Source | SS df MS Number of obs = 200 -------------+------------------------------ F( 5, 194) = 5.67 Model | 2278.24419 5 455.648837 Prob > F = 0.0001 Residual | 15600.6308 194 80.4156228 R-squared = 0.1274 -------------+------------------------------ Adj R-squared = 0.1049 Total | 17878.875 199 89.843593 Root MSE = 8.9675
------------------------------------------------------------------------------ write | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- _Ifemale_1 | 5.566752 1.366513 4.07 0.000 2.871622 8.261882 _Ise1Wfe0 | -2.953191 2.659326 -1.11 0.268 -8.198093 2.29171 _Ise1Wfe1 | -1.75 2.046537 -0.86 0.394 -5.786318 2.286318 _Ise2Wfe0 | -3.308877 2.117528 -1.56 0.120 -7.485208 .8674534 _Ise2Wfe1 | -4.715517 2.109094 -2.24 0.027 -8.875215 -.5558195 _cons | 52.45513 .6832567 76.77 0.000 51.10756 53.80269 ------------------------------------------------------------------------------
Having done this test, we can test the simple effects of ses for males like this.
. test _Ise1Wfe0 _Ise2Wfe0
( 1) _Ise1Wfe0 = 0 ( 2) _Ise2Wfe0 = 0
F( 2, 194) = 2.61 Prob > F = 0.0765
and the simple effects of ses for females like this.
. test _Ise1Wfe1 _Ise2Wfe1
( 1) _Ise1Wfe1 = 0.0 ( 2) _Ise2Wfe1 = 0.0
F( 2, 194) = 4.25 Prob > F = 0.0157
Also see
Manual: [U] 23 Estimation and post-estimation commands, [R] xi On-line: help for est, postest
Author ------ Michael Mitchell & Phil Ender Academic Technology Services UCLA mnmatucla.edu enderatucla.edu