⇤ ← Revision 1 as of 2024-05-31 17:12:14
Size: 1490
Comment: Initial commit
|
← Revision 2 as of 2025-04-04 01:03:15 ⇥
Size: 1490
Comment: Standardize
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
= Stata Xi = | = Stata xi = |
Stata xi
The xi prefix command expands categorical variables into indicator variable sets.
Usage
use http://stata-press.com/data/r14/auto, clear xi: regress mpg i.rep78
This is equivalent to running something like:
levelsof rep78, local(levels) foreach l of local levels { generate dummy_`l' = rp78 == `l' } regress mpg dummy_2 dummy_3 dummy_4 dummy_5
Syntax
The primary use of xi is to take a command like:
xi: regress y i.x1
...and expand the categorical variable x1 into a set of indicator terms for each category. By default, these would be named _Ix1_1, _Ix1_2, and so on. (These variables will persist.) The first such indicator is excluded from the underlying modeling command.
xi also can create interaction terms. For example:
xi: regress y i.x1*i.x2
This creates an indicator for all interactions and all main effects.
If x2 were a continuous variable instead, the more appropriate syntax is one of:
xi: regress y i.x1*x2
...which again creates an indicator for all interactions and all main effects; or...
xi: regress y i.x1|x2
...which again creates an indicator for all interactions and the main effect of x2, but omits the main effect of x1.