I ran a regression based on a "giant" panel data with a bunch of unit fixed effects. So I employed function "felm()" from package "lfe". In addition, I have an interaction term of two continuous variables in the regression. But when plotting how the marginal effects of x on y vary with x2, it seems that the objects produced by "felm()" are often incompatible to most plotting functions like "ggplot", "interplot()" and "meplot". But I have to use "felm()" because I need to control for a large amount of unit fixed effects (like people do by "reghdfe" in Stata). So, how could I address this issues in R? Feel free to let me know some ways out. Thanks!
Here is an example about how interplot() does not work with felm():
# An example data:
library(lfe)
library(ggplot2)
library(interplot)
oldopts <- options(lfe.threads=1)
x <- rnorm(1000)
x2 <- rnorm(length(x))
id <- factor(sample(10,length(x),replace=TRUE))
firm <- factor(sample(3,length(x),replace=TRUE,prob=c(2,1.5,1)))
year <- factor(sample(10,length(x),replace=TRUE,prob=c(2,1.5,rep(1,8))))
id.eff <- rnorm(nlevels(id))
firm.eff <- rnorm(nlevels(firm))
year.eff <- rnorm(nlevels(year))
y <- x + 0.25*x2 + id.eff[id] + firm.eff[firm] +
year.eff[year] + rnorm(length(x))
mydata <- data.frame(cbind(y, x, x2, id, firm, year))
# Regression using felm():
reg1 <- felm(y ~ x + x2 + x:x2|id+firm+year|0|id, data=mydata)
summary(reg1)
# Using interplot() to plot marginal effects
interplot(m=reg1, var1="x", var2="x2", ci=0.9)
Then errors appear:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘sim’ for signature ‘"felm"’
Also I tried meplot() but it still does not work:
# Using meplot() to plot marginal effects
library(evir)
meplot(model=reg1, var1="x", var2="x2", int="x:x2", vcov=vcov(reg1), data=mydata)
I got an error:
Error in meplot(model = reg1, var1 = "x", var2 = "x2", int = "x:x2", vcov = vcov(reg1), :
(list) object cannot be coerced to type 'double'