📄 xi.hlp
字号:
{smcl}
{* 18mar2005}{...}
{cmd:help xi}{right:dialog: {bf:{dialog xi}}}
{hline}
{title:Title}
{p2colset 5 15 17 2}{...}
{p2col :{hi:[R] xi} {hline 2}}Interaction expansion{p_end}
{p2colreset}{...}
{title:Syntax}
{p 8 14 2}
{cmd:xi} [{cmd:,} {opt pre:fix(string)}] {it:term(s)}
{p 8 14 2}
{cmd:xi} [{cmd:,} {opt pre:fix(string)}] {cmd::} {it:any_stata_command}
{it:varlist_with_terms} {it:...}
{phang}
where a {it:term} has the form
{col 9}{cmd:i.}{it:varname}{col 39}or{col 48}{cmd:I.}{it:varname}
{col 9}{cmd:i.}{it:varname1}{cmd:*i.}{it:varname2}{col 48}{cmd:I.}{it:varname1}{cmd:*I.}{it:varname2}
{col 9}{cmd:i.}{it:varname1}{cmd:*}{it:varname3}{col 48}{cmd:I.}{it:varname1}{cmd:*}{it:varname3}
{col 9}{cmd:i.}{it:varname1}{cmd:|}{it:varname3}{col 48}{cmd:I.}{it:varname1}{cmd:|}{it:varname3}
{pstd}
{it:varname}, {it:varname1}, and {it:varname2} denote numeric or string
categorical variables. {it:varname3} denotes a continuous, numeric variable.
{title:Description}
{pstd}
{cmd:xi} expands terms containing categorical variables into indicator
(also called dummy) variable sets by creating new variables, and, in the
second syntax ({bind:{cmd:xi:} {it:any_stata_command}}), executes the
specified command with the expanded terms. The dummy variables created are
{p 8 32 2}{cmd:i.}{it:varname}{space 15}Creates dummies for categorical
variable {it:varname}.
{p 8 32 2}{cmd:i.}{it:varname1}{cmd:*i.}{it:varname2}{space 3}Creates dummies
for categorical variables {it:varname1} and {it:varname2}: and all
interactions and main effects
{p 8 32 2}{cmd:i.}{it:varname1}{cmd:*}{it:varname3}{space 5}Creates dummies for
categorical variable {it:varname1} and continuous variable {it:varname3}: all
interactions and main effects.
{p 8 32 2}{cmd:i.}{it:varname1}{cmd:|}{it:varname3}{space 5}Creates dummies for
categorical variable {it:varname1} and continuous variable {it:varname3}: all
interactions and main effect of {it:varname3}, but no main effect of
{it:varname1}.
{title:Options}
{phang}
{opt prefix(string)} allows you to choose a prefix other than {hi:_I} for the
newly created interaction variables. The prefix cannot be longer than 4
characters. By default, {cmd:xi} will create interaction variables starting
with {hi:_I}. When you use {cmd:xi}, it drops all previously
created interaction variables starting with the prefix specified in the
{opt prefix(string)} option or with {hi:_I} by default. Therefore, if you
want to keep the variables with a certain prefix, specify a different prefix
in the {opt prefix(string)} option.
{phang}
{opt noomit} prevents {cmd:xi} from omitting groups. This option provides a
way to generate an indicator variable for every category of one or more
variables, and is useful in combination with the {opt noconstant} option of a
regression estimation command.
{title:Examples}
{psee}{cmd:. xi: logistic outcome weight i.agegrp bp}{p_end}
{psee}{cmd:. xi: logistic outcome weight bp i.agegrp i.race}{p_end}
{psee}{cmd:. xi: logistic outcome weight bp i.agegrp*i.race}{p_end}
{psee}{cmd:. xi: logistic outcome bp i.agegrp*weight i.race}{p_end}
{psee}{cmd:. xi: logistic outcome bp i.agegrp|weight i.race}{p_end}
{psee}{cmd:. xi: logistic outcome bp i.agegrp*weight i.agegrp*i.race}{p_end}
{psee}{cmd:. xi, prefix(_S) : logistic outcome weight i.agegrp bp}{p_end}
{title:Summary of {cmd:i.}{it:varname}}
{phang}
1. {it:varname} may be string or numeric.
{phang}
2. Indicator (dummy) variables are created automatically.
{phang}
3. By default, the dummy-variable set is identified by dropping
the dummy corresponding to the smallest value of the variable (how to specify
otherwise is discussed below).
{phang}
4. The new dummy variables are left in your dataset. By default, the names
of the new dummy variables start with {hi:_I}, therefore you can drop them by
typing "{hi:drop _I*}". You do not have to do this; each time you use
{cmd:xi}, any previously created automatically generated dummies with the same
prefix as the one specified in the {cmd:prefix()} option ({hi:_I} by default)
are dropped and new ones created.
{phang}
5. The new dummy variables have variable labels so you can
determine to what they correspond by typing "{cmd:describe}" or
"{cmd:describe _I*}"; see {helpb describe}.
{phang}
6. {cmd:xi} may be used with any Stata command (not just
{cmd:logistic}).
{title:Summary of controlling the omitted dummy}
{pstd}
{cmd:i.}{it:varname} omits the first group by default but if you define
{phang2}
{cmd:char _dta[omit] "prevalent"}
{pstd}
then the default behavior changes to that of dropping the most prevalent
group. You can restore the default behavior by typing
{phang2}
{cmd:char _dta[omit]}
{pstd}
Either way, if you define a variable characteristic of the form
{phang2}
{cmd:char} {it:varname}{cmd:[omit]} {it:#}
{pstd}
or, if {it:varname} is a string,
{phang2}
{cmd:char} {it:varname}{cmd:[omit]} {cmd:"}{it:string_literal}{cmd:"}
{pstd}
then the specified value will be omitted.
Examples:
{phang2}
{cmd:. char agegrp[omit] 1}{p_end}
{phang2}
{cmd:. char race[omit] "White"} {space 1} (for {hi:race} a string variable){p_end}
{phang2}
{cmd:. char agegrp[omit]} {space 7} (to restore default)
{title:Interpreting output}
{cmd:. xi: regress mpg i.rep78}
{txt}i.rep78{right:_Irep78_1-5 (naturally coded; _Irep78_1 omitted) }
{it:(output from regress appears)}
{pstd}
Interpretation: {cmd:i.rep78} expanded to the dummies {hi:_Irep78_1},
{hi:_Irep78_2}, ..., {hi:_Irep78_5}. The numbers on the end are "naturally"
coded in the sense that {hi:_Irep78_1} corresponds to {hi:rep78}==1,
{hi:_Irep78_2} to {hi:rep78}==2, etc. Finally, the dummy for {hi:rep78}==1
was omitted.
{cmd:. xi: regress mpg i.make}
{txt}i.make{right:_Imake_1-74 (_Imake_1 for make==AMC Concord omitted) }
{it:(output from regress appears)}
{pstd}
Interpretation: {cmd:i.make} expanded to {hi:_Imake_1}, {hi:_Imake_2},
..., {hi:_Imake_74}. The coding is not natural because make is a string
variable. {hi:_Imake_1} corresponds to one make, {hi:_Imake_2} another, and
so on. We can find out the coding by typing "{cmd:describe}". {hi:_Imake_1}
for the AMC Concord was chosen to be omitted.
{title:How {cmd:xi} names variables}
{pstd}
The names {cmd:xi} assigns to the dummy variables it creates are of the form:
{it:<prefix>}{it:<stub>}{hi:_}{it:<groupid>}
{pstd}
By default, the prefix is {hi:_I}:
{hi:_I}{it:<stub>}{hi:_}{it:<groupid>}
{pstd}
You may subsequently refer to the entire set of variables by
{it:<prefix>}{it:<stub>}{cmd:*}.
{pstd}
For example:
name{col 25}= {hi:_I} + {it:<stub>} + {hi:_} + {it:<groupid>}{col 61}Entire set
{hline 62}
_Iagegrp_1 _I agegrp _ 1{col 61}_Iagegrp*
_Iagegrp_2 _I agegrp _ 2{col 61}_Iagegrp*
_IageXwgt_1 _I ageXwgt _ 1{col 61}_IageXwgt*
_IageXrac_1_2 _I ageXrac _ 1_2{col 61}_IageXrac*
_IageXrac_2_1 _I ageXrac _ 2_1{col 61}_IageXrac*
{title:{cmd:xi} as a command rather than a command prefix}
{pstd}
{cmd:xi} can be used as a command prefix or as a command by itself. In the
latter form, {cmd:xi} merely creates the indicator and interaction variables.
Equivalent to typing,
{phang}
{cmd:. xi: regress y i.agegrp*wgt}
is
{cmd:. xi i.agegrp*wgt}
{txt}i.agegrp{right:_Iagegrp_1-4 (naturally coded; Iagegrp_1 omitted) }
i.agegrp*wgt{right:_IageXwgt_1-4 (coded as above) }
{phang}
{cmd:. regress y _Iagegrp* _IageXwgt*}
{title:Warnings}
{p 4 6 2}- {cmd:xi} creates new variables in your data; most are {hi:byte}s but
interactions with continuous variables will have the storage type of the
underlying continuous variable; see {help data types}.
{p 4 6 2}- when using {cmd:xi} with an estimation command, you may get the
message "{err:matsize too small}". If so, see {help matsize}.
{title:Also see}
{psee}
Manual: {bf:[R] xi}{p_end}
{psee}
Online: {help prefix}, {help estcom}, {help postest}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -