空间杜宾模型和检验以及结果解释stata源代码空间权重矩阵误差模型SEM时间个体固定效应等
含原始演示数据、计算代码、计算过程、参考文献
1. 演示数据包含中国 30 个城市 2004-2016 年的数据(由于数据不全,除去西藏)一个被解释变量 y,三个解释变量 x1、x2、x3,四个控制变量 a1、a2、a3、a4 共 390 组观测值。2. 本文使用 stata15.1 版本3. 未经作者允许请勿在将此文件及其附件在网络上传播4. 本文主要参考资料为陈强的空间计量经济学,部分文件已放在相关资料文件夹中5. 本文的相关 stata 运行代码已标黄,读者可以根据自己需要微调代码,若有问题可以联系作者最后修订日期:2020/3/10第一次修订内容:1.文档错字勘误 2.关于 hausman 检验值为负情况的特殊说明 3.检验结果修正4.增加输出结果为论文格式第二次修订内容:1.增加了 moran 指数的 for 循环输出 2. 增加了安装命令方法的 pdf 3.增加生成对数和缺失值的处理 4.wald 检验修正 5.一些代码的说明 6.增加了空间杜宾模型的分解效应结果和解释
stata程序代码
**一、变量的描述性统计
sum y x1 x2 x3 a1 a2 a3 a4
***二、空间计量模型准备工作
gen lnx1 = ln(x1)
gen lnx2 = ln(x2)
gen lnx3 = ln(x3)
replace lnx1 =0 if missing(lnx1)
***三、空间权重矩阵制作
spatwmat using W.dta, n(W) standardize
matrix list W
***四、空间相关性检验
**Moran’ s I指数
xtset id year
spatwmat using W.dta, n(W) standardize
preserve
keep if year==2004 //改变年份2004
spatgsa y,weights(W) moran geary twotail
restore
......
*个体固定效应
xsmle y x* a*, model(sdm) wmat(W) type(ind) nolog effects fe
*双固定效应
xsmle y x* a*, model(sdm) wmat(W) type(both) nolog effects fe
**空间误差模型(SEM)
xtset id year
spatwmat using D.dta,name(W) standardize
*随机效应模型
xsmle y x* a*, model(sem) emat(W) type(both) nolog effects re
*时间固定效应
xsmle y x* a*, model(sem) emat(W) type(time) nolog effects fe
*个体固定效应
xsmle y x* a*, model(sem) emat(W) type(ind) nolog effects fe
*双固定效应
xsmle y x* a*, model(sem) emat(W) type(both) nolog effects fe
**空间滞后模型(SLM)
xtset id year
spatwmat using W.dta,name(W) standardize
*随机效应模型
xsmle y x* a*, model(sar) wmat(W) type(both) nolog effects re
*时间固定效应
xsmle y x* a*, model(sar) wmat(W) type(time) nolog effects fe
*个体固定效应
xsmle y x* a*, model(sar) wmat(W) type(ind) nolog effects fe
*双固定效应
xsmle y x* a*, model(sar) wmat(W) type(both) nolog effects fe
***六、相关检验
**6.1LM检验
clear all
use data
use W //W为矩阵名称
spcs2xt a1-a30,matrix(aaa)time(13) //扩大权重矩阵数量,因为W是30x30而样本有390组观测值,需要扩大13倍,此时会生成aaaxt.dta的390x390的权重矩阵
spatwmat using aaaxt,name(W)
clear
use data //调用论文数据data
xtset id year
reg y x1 x2 x3 a1 a2 a3 a4
spatdiag,weights(W)
.....