xuyiqing / fect

fixed effect counterfactual estimators
Other
53 stars 20 forks source link

Adding interaction terms #29

Open QLgogo opened 1 year ago

QLgogo commented 1 year ago

Hi, thanks for this great estimator. I encountered problems when I tried to add interaction terms into the regression estimated by "fect" function. I tried different ways:

Way 1: out.mc <- fect(formula = DV ~ IV1 + IV2 + IV1:IV2 + controls, data = df, index = c("newid", "year"), force = "two-way", lambda = c(0.5), method = "mc", CV = TRUE, pre.period = NULL, se = TRUE, nboots = 100, parallel = FALSE, seed = 9799) The results did not report the coefficient of the interaction term but showed coefficients of IV1 and IV2.

Way2: df <- transform(df, inter = IV1*IV2) out.mc <- fect(formula = DV ~ IV1 + IV2 + inter + controls, data = df, index = c("newid", "year"), force = "two-way", lambda = c(0.5), method = "mc", CV = TRUE, pre.period = NULL, se = TRUE, nboots = 100, parallel = FALSE, seed = 9799) The results returned errors (copied below) and said interaction terms has collinearity issues. However, I did not see collinearity issues when estimating the regression with xtreg or reghdfe.

"The variable 'x.7' has been removed because of collinearity (see $collin.var). Error in beta0CV[, , i] <- beta0cv : number of items to replace is not a multiple of replacement length"

Could you help with this interaction issue? Many thanks in advance!