-1

I have a panel data model with various explanatory variables, but I am mainly interested in the effect of just one of them. I would like to visualize my model by putting all the other explanatory variables at their means and plot my model on a scatterplot of my dependent variable and my main explanatory variable.

How can I code this in R?

Thank you very much for your answer.

7Luke7
  • 15
  • 4

1 Answers1

1

What you looking for is the marginal effect of one variable, one quick way is to use sjPlot, although I am not sure with "a panel data model", does it mean you are using a linear model lm() and a panel regression plm(), below is an example with lm() :

library(sjPlot)
library(ggplot2)

fit <- lm(mpg ~ hp + disp + drat, data = mtcars)
plot_model(fit, type = "pred", terms = "hp")

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72