4
I am using the plm package to perform analysis in a panel. To structure the base as a panel, I used the function pdata.frame
of the same package. With this, I had as return a panel with the following features:
Dai, I would like to run a regression using instrumental variables with the following formula:
saida <- plm(formula = X4 ~ X1 | . ~ X2 + X3 + Ano.Mes + id, data = as.matrix(painel),model = "within", index = c("id", "Ano.Mes"))
However, I get the following error:
Error in x[, ! na.check] : (subscript) Submit your request
Does anyone have any suggestions to fix this error?
I created this example with the Iris data structure of the R database and the same error occurs:
data(iris)
tst <- iris[1:120,]
tst$mes <- rep(1:12,times = 10)
tst$ano <- unlist(lapply(2007:2016, function(x) rep(x, times = 12)))
tst$ano.mes <- paste(tst$ano,"m",tst$mes, sep = "")
painel <- pdata.frame(tst, index = c("Species","ano.mes"))
modelo <- plm(formula = Sepal.Length ~ Sepal.Width | . ~ Petal.Length + Petal.Width + Species + ano.mes, data = as.matrix(painel), index = c("Species", "mes.ano"), model = "within")
It would be interesting if we could reproduce your code in order to verify what error is in it. Without having access to more information, my hypothesis is that the logical vector
na.check
has more elements than the number of columns ofx
. However, I don’t know what it isx
, nor howna.check
was built. So I suggest that the question be edited and more details about it be included.– Marcus Nunes
has some reason to transform the
painel
inmatrix
in the code? I find it strange you turn it topdata.frame
and then usedata = as.matrix(painel)
. It doesn’t end up undoing the transformation?– Daniel Falbel
– Otto Tavares