Troubleshooting GWPR/PLM duplicate couples error

35 Views Asked by At

I am trying to run a Geographically weighted panel regression model as seen below. However I keep on getting an error of duplicate ids.

     bw.GWPR(formula = formula1, data = finalprepostdataset3,
                    SDF = finalprepostdataset_sp,
                    index = c("county_id", "season"),
                    adaptive = TRUE, approach = "AIC",
                    p = 2, effect = "twoways", model = "within",
                    doParallel=T, cluster.number=4,
                    kernel = "bisquare", longlat = FALSE, bigdata = T)
Error in { : task 1 failed - "duplicate couples (id-time)


finalprepostdataset_sp is a spatial copy of finalprepostdataset3. I read guides to get rid of this problem (my understanding is that it derives from the way plm handles panel data) but I still am getting errors. To be clearer, I can run this code successfully:

plm(
  formula=formula1,
  data=finalprepostdataset3,
  effect = "time",
  model = "within",
  index = c("county_id", "season"),
)

And:

any(table(index(finalprepostdataset3$county_id, finalprepostdataset3$season), useNA = "ifany")!=1)
FALSE

Indicating, as I understand it, no duplicates.

But the first code would not run.

Any help would be appreciated. Posting here due to people's familiarity with plm.

1

There are 1 best solutions below

0
On

Hard to tell without a reproducible example. Function bw.GWPR seems to stem from package GWPR.light and plm from package plm, both of which are not indidicated in the question.

If you plm statement runs successfully without a warning, you should be safe not to have doublicated compbinations of the observational unit (county_id) and time dimension (season) in your data.

However, to check you would leave out the index function in your test (or used index on a pdata.frame (not on variables))

any(table(index(<your_pdata.frame>), useNA = "ifany")!=1)
any(table(finalprepostdataset3$county_id, finalprepostdataset3$season, useNA = "ifany")!=1)