SPML(空间面板模型):lag.listw | 中出现错误不平衡面板

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

我正在从 splm 库制作空间面板模型,但我无法制作固定或随机效应模型,因为它是一个不平衡面板。

数据

数据shp文件

可重现的示例

library(dplyr)
library(Hmisc)
library(sf)
library(plm)
library(splm)
library(spdep)
data = read.csv("data.csv", colClasses=c(id="factor"))
map = st_read("nxparroquias.shp")
colnames(map)[1] = "id"

balanced = data %>% 
  group_by(id) %>%
  #drop_na() %>% 
  filter(all(c(2013:2018) %in% year)) %>% 
  ungroup() %>% 
  filter(id %in% unique(map$id))

map = map %>% 
  filter(id %in% unique(balanced$id))
pt = spdep::poly2nb(map)
ptw = spdep::nb2listw(pt, zero.policy = TRUE)

describe(balanced$id)
#balanced$id 
#n  missing distinct 
#5832        0      972 

describe(map$id)
#map$id 
#n  missing distinct 
#972        0      972 

#checks if the data are balanced
plm::is.pbalanced(balanced$id,balanced$year)
#[1] TRUE

p_balanced = pdata.frame(balanced, index = c("id", "year"))  #same issues

池化

md1 = splm::spml(data = balanced,
                 y ~ x1+x2+x3, 
                 index =  c("id", "year"),
                 zero.policy = TRUE,
                 model = "pooling",
                 listw = ptw)
summary(md1)

#ML panel with , spatial error correlation 
#
#Call:
#  spreml(formula = formula, data = data, index = index, w = listw2mat(listw), 
#         w2 = listw2mat(listw2), lag = lag, errors = errors, cl = cl, 
#         zero.policy = TRUE)
#
#Residuals:
#  Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#-14.860  -3.213   0.539   0.003   3.194  13.181 
#
#Error variance parameters:
#  Estimate Std. Error t-value Pr(>|t|)    
#rho 0.087841   0.019622  4.4767 7.58e-06 ***
#  
#  Coefficients:
#  Estimate Std. Error t-value  Pr(>|t|)    
#(Intercept)  5.1373431  0.0972298 52.8371 < 2.2e-16 ***
#  x1           0.0423977  0.0098276  4.3141 1.602e-05 ***
#  x2           0.1109780  0.0083800 13.2432 < 2.2e-16 ***
#  x3          -0.0444174  0.0096522 -4.6018 4.189e-06 ***
#  ---
#  Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

FE

md2 = splm::spml(data = balanced,
                 y ~ x1+x2+x3, 
                 index =  c("id", "year"),
                 zero.policy = TRUE,
                 model = "within",
                 listw = ptw)

具有可重现的示例固定效果

lag.listw(listw, u, Zero.policy = Zero.policy) 中的错误: 物体长度不同

用我的原始数据

spfeml 中的错误(公式 = 公式,数据 = 数据,索引 = 索引,listw = listw,: 不平衡面板无法使用估算方法

重新

具有随机效果

.C64("aplsb1", SIGNATURE = c(SS$signature, SS$signature, "double", 中的错误: 参数 7 中的 NA 和 'NAOK = FALSE' (dotCall64)

r geospatial panel-data plm spml
1个回答
0
投票

您好,您有什么问题吗? Je suis aux prises avec le même problème.

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.