You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A very common operation in econometric analyses is to interact a categorical variable with another variable (for example, in difference-in-differences regressions).
To very flexibly handle such interactions, the fixest R package has introduced a novel operator, the i() operator.
It allows to easily set reference levels for individual categorical variables and their interaction. On top, it provides sugar for binning levels of categorical variables.
Would you consider to add the i() operator to formulaic's transforms? The best starting point to learn about it are the fixest docs, but I have also attached some examples and comparisons to formulaic below.
y, X=model_matrix("y ~ C(factor1, contr.treatment('a')):factor2", data=df)
X.columns#Index(['Intercept', # 'C(factor1, contr.treatment('a'))[a]:factor2',# 'C(factor1, contr.treatment('a'))[b]:factor2',# 'C(factor1, contr.treatment('a'))[c]:factor2'],# dtype='object')# so need to drop column 'C(factor1, contr.treatment('a'))[a]:factor2' by hand
Binning
# binning # group fe levels a & b into 'bin'fit= feols(y~ i(factor1, factor2, bin=list(bin= c("a","b"))), data=df)
X=fixest:::model.matrix.fixest(fit)
X|> colnames()
# [1] "(Intercept)" "factor1::bin:factor2" "factor1::c:factor2"
The text was updated successfully, but these errors were encountered:
Hi @matthewwardrop ,
A very common operation in econometric analyses is to interact a categorical variable with another variable (for example, in difference-in-differences regressions).
To very flexibly handle such interactions, the fixest R package has introduced a novel operator, the
i()
operator.It allows to easily set reference levels for individual categorical variables and their interaction. On top, it provides sugar for binning levels of categorical variables.
Would you consider to add the
i()
operator toformulaic
's transforms? The best starting point to learn about it are the fixest docs, but I have also attached some examples and comparisons toformulaic
below.Easily set the reference level for one categorical
This could be easily achieved by a stateful transform in
formulaic
:Interacting Variables
Two variables, reference level used
Binning
The text was updated successfully, but these errors were encountered: