Differences between revisions 1 and 4 (spanning 3 versions)
Revision 1 as of 2024-05-31 17:12:14
Size: 1490
Comment: Initial commit
Revision 4 as of 2025-10-24 18:38:48
Size: 1498
Comment: Fix capitalization
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
The '''`xi`''' prefix command expands categorical variables into indicator variable sets. The '''`-xi-`''' prefix command expands categorical variables into indicator variable sets.
Line 35: Line 35:
The primary use of `xi` is to take a command like: The primary use of `-xi-` is to take a command like:
Line 43: Line 43:
`xi` also can create interaction terms. For example: `-xi-` also can create interaction terms. For example:
Line 71: Line 71:
[[https://www.stata.com/manuals/rxi.pdf|Stata manual for xi]] [[https://www.stata.com/manuals/rxi.pdf|Stata manual for -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.


See also

Stata manual for -xi-


CategoryRicottone

Stata/Xi (last edited 2025-10-24 18:38:48 by DominicRicottone)