I'm currently working on some pooled regression and a fixed effects within estimator model for panel data analysis in R. I've estimated the pooled and FE model using the library(plm)
function:
m_pooled = plm(homiciderate ~ humanrightsviol + freedom + lngdp + econgrowth + popdensity + male1564,
data = df_hom, index = c("country","year"), model="pooling")
m_fixedeffects <- plm(homiciderate ~ humanrightsviol + freedom + lngdp + econgrowth + popdensity + male1564,
data = df_hom, index = c("country","year"),
model="within")
I'm now looking to plot these both together using the following code:
plot_fixedeffects <- plot(m_fixedeffects, type = "effects", index = 2, col = "red")
plot_pooled <- plot(m_pooled, type = "effects", index = 2, col = "blue")
combined_plot <- plot_fixedeffects + plot_pooled
combined_plot <- combined_plot + labs(title = "Fixed Effects Within Estimator vs Pooled Regression",
x = "Time",
y = "Effect Estimate") +
scale_color_manual(values = c("red", "blue"),
labels = c("Fixed Effects Within Estimator", "Pooled Regression"),
name = "Estimation Method")
print(combined_plot)
However, when I do so, I receive the error message as follows:
Error in xy.coords(x, y) : 'x' and 'y' lengths differ
In addition: Warning message:
In meanx * beta :
longer object length is not a multiple of shorter object length
For information, I was expecting an outcome similar to this plot, but have not been able to produce it:
Is there any reason for this?