Fixest-style i() operator for categorical encoding with interactions.
Parameters
Name
Type
Description
Default
data
array - like
The categorical variable to encode.
required
var2
array - like
Optional second variable to interact with. A numeric var2 gives continuous slopes; a non-numeric var2 is a factor. Wrap a numeric var2 in C(), as in i(f, C(k)), to treat it as a factor.
None
ref
Hashable
Reference level to drop from data.
None
ref2
Hashable
Reference level to drop from a factor var2. Raises ValueError for a continuous var2.
None
bin
dict
Mapping of new_level -> [old_levels] for binning data.
None
bin2
dict
Mapping of new_level -> [old_levels] for binning a factor var2. Raises ValueError for a continuous var2.
None
Returns
Name
Type
Description
FactorValues
The encoded factor values, ready for use in a formulaic model matrix.
Examples
Implements the i() operator and is used by writing i(...) in a formula rather than by calling it directly. Expands a categorical variable into indicators, optionally dropping a reference level and interacting it with a second variable. Commonly used for event study specifications. See the formula syntax tutorial.