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 subscriptj
has size 2366.
and I have no idea what it means or how I can possibly deal with it.