0

I found this answer for excluding NAs in the indices for the plm function ( How to deal with NA in index for Panel data ) and included it in my code and duplicated the exlusion since I have NAs in both indices for the plm:

result <- plm(VarX ~ VarY + VarZ, data = mydata[which(!is.na(mydata$ID)),!is.na(mydata$year)], index = c("ID","year"), model="within")

Now, R gives me a error message saying:

Error in vectbl_as_col_location(): ! Must subset columns with a valid subscript vector. ℹ Logical subscripts must match the size of the indexed input. ✖ Input has size 6 but subscript j has size 2366.

and I have no idea what it means or how I can possibly deal with it.

Helix123
  • 3,502
  • 2
  • 16
  • 36
  • 1
    I am not sure but this doesn't look right: `mydata[which(!is.na(mydata$ID)),!is.na(mydata$year)]`, I don't know what is contained in mydata but it seems that it should be `mydata[!is.na(mydata$ID) & !is.na(mydata$year),]` – PKumar Jun 15 '22 at 09:37
  • 1
    thank you for your correction, it managed to do the regression! thanks a lot! – Matteo G. M. Pastore Jun 15 '22 at 10:08
  • The error actually stems from subsetting itself, more specifically from subsetting a tibble (as `vectbl_as_col_location` is from the package tibble). Thus, this is not related to package `plm`. My suggestion is to first prepare your data (and subset to exclude the NA's in the index variables), then to create a `pdata.frame` and input the pdata.frame into `plm`'s `data` argument. – Helix123 Jun 15 '22 at 17:46

0 Answers0