plm – Error with indexing pdata.frame in r using pgmm()

I am a student and struggling with a specific problem regarding the pgmm() function of the plm package in R. I have a pdata.frame for which I want to use the pgmm function for a dynamic panel model. However, the following error occurs:

Error in pdata.frame(data, index): variable NA does not exist (time index)

There is no variable called NA and in neither the id nor time index are there any NAs.
The index is specified as "country" for id and "year" for time index. I have made sure to remove duplicates. I have tried all kinds of different combinations: Specified the index only when creating the pdata.frame, specifying the index only in the pgmm function, both, and leaving out the index = c() part altogether while making sure the two variable supposed to be used as index were the first two columns in the data set. Also, I tried setting the "year" variable as factor, numeric or character or setting drop.index to TRUE or FALSE. Nothing helped. Here is part of the code:

df_p <- pdata.frame(df_2, index= c("country", "year"), drop.index = FALSE)

z1 <- pgmm(gini_disp ~ lag((gini_disp), 1:2) + lag((cumcrisis), 0:1)+ lag((GDPcap), 0:1) + lag((shock), 0:1) | lag(gini_disp), 2:40) data = df_p, index = c("country", "conyear"), effect = "individual", model = "onestep")

Running the second function gives the error. In this case country and year should be indexed twice, but as said above this happens in all combinations. Any idea?

Read more here: Source link