0
I’m running multiple linear regressions on R. Initially I circled with the "pooled" effect and it worked fine. When I try to do the same with the effect "Within" and "Random" shows the following error:
Error in class(x) <- setdiff(class(x), "pseries") : invalid to set the class to Matrix unless the Dimension attribute is of length 2 (was 0)
Can anyone shed any light on the mistake I’m making? I take this opportunity to apologize if I’m doing something really stupid.
##INSTALAÇÃO DE PACOTES##
list.of.packages <- c("AER","tidyverse", "gdata","DT","ggthemes", "RCurl", "readxl", "zoo", "ggcorrplot", "reprex", "ggmap","ggalt", "devtools", "gapminder", "gganimate", "cowplot", "xts", "PerformanceAnalytics", "fmsb", "viridis", "tidyverse", "sandwich", "lmtest", "qqman", "car", "dplyr", "stargazer", "ggplot2", "foreign","openintro", "nlme", "OIdata", "gdata", "pdflscape", "doBy","ivpack", "gplots", "psych","plm","cluster.datasets", "readxl")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
lapply(list.of.packages, require, character.only = TRUE)
##
## CAMINHO DO PROJETO##
library(readxl)
library(plm)
Dados <- read_excel("Testes/Dissertreg.xlsx")
##DECLARAÇÃO de VARIÁVEIS
Y <- cbind(Produtividade)
X <- cbind(Racao, Silagem, Preco)
##SETANDO DADOS EM PAINEL
pdata <- pdata.frame(Dados, index=c("id", "t"))
##ESTATÍSTICA DESCRITIVA
summary(Y)
summary(X)
##Pooled OLS Estimator
pooling <- plm(Y ~ X, data = pdata, model = "pooling")
summary(pooling)
##Efeito Fixo ou within
fixo <- plm(Y ~ X, data = pdata, model = "within")
summay(fixo)
##Efeito Aleatório
random <- plm(Y ~ X, data = pdata, model = "random")
summary(random)
By the way, the mistake comes from a
cbind
the most,Y <- Grunfeld$inv
Enough and the rest of the code already runs smoothly. Withcbind
the response vector is a class object"matrix"
.– Rui Barradas
It worked perfectly. Thank you very much.
– Valmor Mantelli Jr.