So I've tried running the following code from a panel dataset of weekly hospital observations and I'm getting a recurrent error, which I believe is driven by plm
:
finalprepostdataset2<-finalprepostdataset%>%
filter(state=="AL"|state=="GA"| state=="NC"| state=="SC"|state=="MI"|state=="FL")%>%
group_by(year, week) %>%
mutate(group = cur_group_id())%>%
ungroup()
finalprepostdataset2<-unique(finalprepostdataset2, by=c("hospital_pk", "group"))
finalprepostdataset_sp<-st_as_sf(x=finalprepostdataset2, crs = "+proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0")
finalprepostdataset_sp <- as(finalprepostdataset_sp, "Spatial")
formula<-y~i(ranking, ref=0)+x+z
result.F.AIC<-GWPR(formula=formula, bw=211.73, data=finalprepostdataset2, SDF=finalprepostdataset_sp,
index=c("hospital_pk", "group"),
adaptive = T, p = 2,
effect = "time", model = "within", kernel = "gaussian", longlat = FALSE)
Warning message:
In pdata.frame(data, index) :
duplicate couples (id-time) in resulting pdata.frame
to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
I've read the answers here and here and here, and maybe I'm a bit confused because hospital-and-week-level data is the lowest level of fixed effects available. There are no duplicate values:
finalprepostdataset2<-finalprepostdataset%>%
filter(state=="AL"|state=="GA"| state=="NC"| state=="SC"|state=="MI"|state=="FL")%>%
group_by(year, week) %>%
mutate(group = cur_group_id())%>%
ungroup()%>%
get_dupes(hospital_pk, group)
No duplicate combinations found of: hospital_pk, group
So I could use some help understanding why I'm still getting errors.