Interacts a variable with another treated as a factor, and sets a reference
i(var, fe, ref, confirm = FALSE)interact(var, fe, ref, confirm = FALSE)
A vector.
A vector (of any type). Must be of the same length as var
.
A single value that belongs to the interacted variable (fe
). Can be missing.
Logical, default is FALSE
. If the factor variable has over 100 cases, you need to use confirm = TRUE
to carry on.
It returns a matrix with number of rows the length of var
. The number of columns is equal to the number of cases contained in fe
minus the reference.
In fixest
estimations, instead of using i(var, fe, ref)
, you can instead use the following writing var::fe(ref)
.
coefplot
to plot interactions, feols
for OLS estimation with multiple fixed-effects.
# NOT RUN {
#
# Simple illustration
#
x = rnorm(10)
y = rep(1:4, 3)[1:10]
cbind(x, y, i(x, y, 1))
#
# In fixest estimations
#
# NOTA: in fixest estimations, i(var, fe, ref) is equivalent to var::fe(ref)
data(base_did)
# We interact the variable 'period' with the variable 'treat'
est_did = feols(y ~ x1 + i(treat, period, 5) | id+period, base_did)
# You could have used the following formula instead:
# y ~ x1 + treat::period(5) | id+period
# }
Run the code above in your browser using DataLab