文献来源Prokopczuk, M., et al. (2023). Convenience yield riskAppendix A. Supplementary data【数据+Stata+Python+Matlab】示例代码library(plm)
library(splm)
library(spdep)
setwd("C:\\Download\\1-s2.0-S0140988323000348-mmc2\\code_without_data\\helpers\\paneldata\\numericalchecks")
W = read.table("MunnellW.txt")
W = as.matrix(W)
lw = mat2listw(W)
fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp
# SARAR FE
sararfe <- spgm(fm, data=dataMunnell, listw=lw, lag=TRUE, spatial.error=TRUE, model="within", method="w2sls")
summary(sararfe)
# spatial coefficient (rho) and t statistic
rhofe <- sararfe$rho[1]
rhofe_t <- sararfe$rho[1] / sqrt(sararfe$rho[2])
print(rhofe)
print(rhofe_t)
# SARAR RE
sararre <- spgm(fm, data=dataMunnell, listw=lw, lag=TRUE, spatial.error=TRUE, model="random", method="g2sls")
summary(sararre)
# spatial coefficient (rho) and t statistic
rhore <- sararre$rho[1]
rhore_t <- sararre$rho[1] / sqrt(sararre$rho[2])
print(rhore)
print(rh
………………………………