I am trying to develop a fixed effect regression model for a panel data using the plm package in R. I want to get the correlation between fixed effects and the regressors. Something like the corr(u_i, Xb) that comes in the Stata output. How to get it in R? I have tried the following (using the in-built dataset in the plm package):-
data("Grunfeld", package = "plm")
library(plm)
# build the model
gi <- plm(inv ~ value + capital, data = Grunfeld, model = "within")
# extract the fixed effects fixef(gi)
summary(fixef(gi))
fixefs <- fixef(gi)[index(gi, which = "id")] ## get the fixed effects
newdata <- as.data.frame(cbind(fixefs, Grunfeld$value, Grunfeld$capital))
colnames(newdata) <- c("fixed_effects", "value", "capital")
cor(newdata)
EDIT: I asked this question on cross validated first and I got this reply- "Questions that are solely about programming or carrying out an operation within a statistical package are off-topic for this site and may be closed." Since my question has more to do with a operation in a package, so I guess this is the right place!
How about the following considering functions of plm: