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 (continuous or categorical).
None
ref
Hashable
Reference level to drop from data.
None
ref2
Hashable
Reference level to drop from var2 (only if var2 is categorical).
None
bin
dict
Mapping of new_level -> [old_levels] for binning data.
None
bin2
dict
Mapping of new_level -> [old_levels] for binning 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.