Error using plm - Error in x [! na.check]: (subscript) logical subscript too long

4

I'm using the plm package to do analysis on a dashboard. To structure the base as a panel, I used the pdata.frame function of the same package. With this, I had a panel with the following characteristics:

Dai,Iwouldliketorunaregressionusinginstrumentalvariableswiththefollowingformula:

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) logical subscript too long

Does anyone have any suggestions for solving this error?

I created this example with the Iris data structure of the base of R 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")
    
asked by anonymous 23.08.2016 / 19:15

2 answers

1

I see here that the error may be due to the fact that two formulas are being defined where it should be only one set.

modelo <- plm(formula = Sepal.Length **~** Sepal.Width | .  **~** Petal.Length + Petal.Width + Species + ano.mes, data = (painel), index = c("Species", "mes.ano"), model = "within")

the item "." refers to the formula defined above.

You can see more about this at link

  

4.3. Formulas   There are circumstances where standard formula is not very usefull to > describes a model,   notably while using instrumental variable like estimators: to deal with these situations, we   use the Formula package.   The Formula package provides a class that unables to construct multipart formula, each   part being separated by a pipe sign. plm provides a pFormula object which is a Formula with specific methods.

Using the problem that friend Daniel approached and the problem I am pointing to a possible solution is:

modelo <- plm(formula = Sepal.Length ~ Sepal.Width | . + Petal.Length + Petal.Width + Species + ano.mes, data = (painel), index = c("Species", "mes.ano"), model = "within") 

I hope I have helped. Hugs

    
24.08.2016 / 07:05
1

The first problem is:

  • the package receives a data.frame as input. This can be found in the documentation.
  •   

    date the data.frame,

  • When you are adjusting the model with the array, it gives this error. When you adjust the template with the data.frame, it gives the following error. Probably because of this you thought that the input should be an array.
  •   

    Error in model.frame.default (terms (formula, lhs = lhs, rhs = rhs, data   = data,: object is not a matrix

    This is a problem before running the model. This error is in the function that turns your formula into an array that will be consumed by the model next. That is, it is not a problem specific to the plm package.

    This error is happening, the only thing I can think of is that its formula is incorrect. In fact, I do not know this specification using y ~ a + b | . ~ a + b + c + d

    Note that this no longer works:

    > model.frame.default(. ~ Petal.Length + Petal.Width + Species, data = painel)
    Error in eval(expr, envir, enclos) : object '.' not found
    

    That's all to say: Is your formula correct? Do not you want a formula like: Sepal.Length ~ Sepal.Width | Petal.Length + Petal.Width + Species + ano.mes in which the model runs normally?

        
    23.08.2016 / 21:56