'plm: duplicate couples

I am working with panel data in R, and I want to run a two way panel fixed effects model on my data set so I used plm:

plm1 <- plm(rprofit_acre~dd89+prcp_0410, data=data, effect="twoways", model="within")

and I am getting the error message

"Error in pdim.default(index[[1L]], index[[2L]]) : duplicate couples (id-time)"

I used the suggestion in the error message to see if there are any duplicates of state+year combination with the line

any(table(data$state,data$year)!=1)

and the result was TRUE, meaning that there aren't any duplicates of state+year combination.



Solution 1:[1]

The suggestion in the error message (which you do not reprint fully) is actually table(index(your_pdataframe), useNA = "ifany"). If it prints something differently on your end, use a current version of the package.

You modified that and test for any combinations which appear less or more than once (by != 1). If that yields TRUE, you cannot infer there are not doublicate couples, rather the opposite is true (as there cannot be less than 1 combinations, there must be more than one).

So, you can use the suggestion from the error message to identify the doublicate combinations (your expression just tells you that there are some).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Helix123