在 SLX 中包含特定于单位的时间趋势时下标越界?

问题描述 投票:0回答:0

我尝试使用空间滞后解释变量 (demo_dum) 运行双向固定效应回归,以了解房屋拆除对人均犯罪的影响。但是,当我运行以下代码时,出现此错误:

Error in sum_lm_model$coefficients[K:dvars[1], 1:2, drop = FALSE] : 
  subscript out of bounds

谁能告诉我哪里出了问题?非常感谢。

spatial <- read.csv("Panel0321.csv")

# X_CX and X_CY are the centroid of census tracts
loc_matrix <- cbind(spatial$X_CX, spatial$X_CY)

# find 10 nearest neighbors
kn <- knearneigh(loc_matrix, 10)

# Turn the k-nearest-neighbors object into a neighbors object
nb <- knn2nb(kn)

# converted this neighbor list in a Weight matrix
W <- nb2listw(nb, style = "W")

# spatially lagged explanatory: demo_dum is the indicator that turns on when tract is first treated
SLX.twfe <- lmSLX(per_cap_crime ~ demo_dum + factor(tractce10) + factor(year), data=spatial, listw=W, Durbin = ~demo_dum)
summary(SLX.twfe)

# now I add a tract-specific linear time trend
SLX.trend <- lmSLX(per_cap_crime ~ demo_dum + factor(tractce10) + factor(year) + factor(tractce10)*year, data=spatial, listw=W, Durbin = ~demo_dum)
summary(SLX.trend)
r spatial
© www.soinside.com 2019 - 2024. All rights reserved.