# Workaround for marginal effects and their significance in panel models when there is no such a package (in R)

I figured out that margins (from R, mimics Stata) is a good way to get marginal effects (and their significance, CI, ...) for linear models in R.

Example:

library("car")
library("plm")
library("margins")
data("LaborSupply", package = "plm")

# Linear Regression
linear_model <- lm(lnwg ~ kids + age + I(age^2), data = LaborSupply)

summary(linear_model )
summary(margins(linear_model))


But it does not support any kind of panel model (found several open/unanswered questions on this).

data("Produc", package = "plm")

# Fixed Effects Regression
FE_model <- plm(log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp,
data = Produc,
index = c("state","year"),
method="within")
summary(margins(FE_model))
Error in crossprod(beta, t(X)) : non-conformable arguments


How can I calculate marginal effects for a fixed effects model and test their statistical significance manually? What is the best practice workaround? What is the math behind those calculations? Perhaps I can implement a formula in my FE-case. Worst case would be to transform my data and re-do the analysis in Stata.