clear all
cls
ssc install estout
ssc install logout
// Stata输出统计结果到Excel或word
///导出文件
ssc install corr2docx
corr2docx ///变量名
using corr2.docx, star(*** 0.01 ** 0.05 * .1) fmt(%4.2f)
title("表 2:相关系数矩阵”)
ssc install t2docx
*t2docx 变量名 using 3.docx,replaceby(foreign) ///title("表 3: t 检验")
*莫兰
cd C:\xxxx\xxxxx\xxxx\xxxxxx\找数据
xls2dta:import excel data反地理矩阵.xlsx,first case(lower)
xls2dta:import excel data正地理矩阵.xlsx,first case(lower)
xls2dta:import excel dataaaa.xlsx,first case(lower)
xls2dta:import excel databbb.xlsx,first case(lower)
xls2dta:import excel 空间权重矩阵.xlsx,first case(lower)
/// 单个excel的单个表单转换为dta文件。这里的firstcase是指将excel转换为dta格式时将excel的第一行作为变量名。
use data反地理矩阵.dta
use data正地理矩阵.dta
use 空间权重矩阵.dta
use databbb.dta
use dataaaa.dta
/// 使用dta文件
search spatwmat
/// 安装molan spatwmat命令
///standardize表示行标准化 命名为W
spatwmat using data反地理矩阵.dta,name(W) standardize
spatwmat using 空间权重矩阵.dta,name(W) standardize
spatwmat using data正地理矩阵.dta,name(W) standardize
save W, replace
/// 保存文件
use W.dta
/// 全局莫兰
spatgsa molan2011 molan2012 molan2013 molan2014 molan2015 molan2016 molan2017 molan2018 molan2019 molan2020, weights(W) moran
logout , save(mytable) word replace:spatgsa molan2011 molan2012 molan2013 molan2014 molan2015 molan2016 molan2017 molan2018 molan2019 molan2020, weights(W) moran
/// 局部莫兰
spatlsa molan2011,weights(W) moran graph (moran) symbol(n)
hold on
spatlsa molan2012,weights(W) moran graph (moran) symbol(n)
spatlsa molan2013,weights(W) moran graph (moran) symbol(n)
spatlsa molan2014,weights(W) moran graph (moran) symbol(n)
spatlsa molan2015,weights(W) moran graph (moran) symbol(n)
spatlsa molan2016,weights(W) moran graph (moran) symbol(n)
spatlsa molan2017,weights(W) moran graph (moran) symbol(n)
spatlsa molan2018,weights(W) moran graph (moran) symbol(n)
spatlsa molan2019,weights(W) moran graph (moran) symbol(n)
spatlsa molan2020,weights(W) moran graph (moran) symbol(n)
/// 莫兰指数图
spatlsa molan2011, weight(W) moran graph (moran) symbol(n)
gen id1 = id
xtset id year
xtreg y x i.year,fe
xtreg y x ,fe
*LM
cd C:\xxxx\xxxx\xxxx\xxxxxx\检验
xls2dta:import excel data.xlsx,first case(lower)
xls2dta:import excel 空间权重矩阵.xlsx,first case(lower)
xls2dta:import excel data反地理矩阵.xlsx,first case(lower)
use 空间权重矩阵.dta
spcs2xt a-ad, matrix(W) time(10)
///扩大矩阵 time倍数(几年)
spatwmat using Wxt.dta,name(ww) standardize
use data.dta
xtset id year
reg y x x2 x5 x6 x8 x9,r
spatdiag,weights(ww)
use data反地理矩阵.dta
spatwmat using data反地理矩阵.dta,name(W) standardize
logout , save(mytable) excel replace:spatdiag,weights(ww)
*HAUSMAN
use 空间权重矩阵.dta
spatwmat using 空间权重矩阵.dta,name(W) standardize
use data反地理矩阵.dta
spatwmat using data反地理矩阵.dta,name(W) standardize
use data.dta
xtset id year
xsmle y x x2 x5 x6 x8 x9, fe model(sdm) wmat(W) type(both) nolog effects
est store fe
xsmle y x x2 x5 x6 x8 x9, re model(sdm) wmat(W) type(both) nolog effects
est store re
/// ind 个体固定 time 时间固定 both 双固定
hausman fe re
use 空间权重矩阵.dta
spatwmat using 空间权重矩阵.dta,name(W) standardize
use data.dta
xtset id year
xsmle y x x2 x8 x9, fe model(sdm) wmat(W) type(both) nolog effects
est store fe
xsmle y x x2 x8 x9, re model(sdm) wmat(W) type(both) nolog effects
est store re
/// ind 个体固定 time 时间固定 both 双固定
hausman fe re
*LR
use 空间权重矩阵.dta
spatwmat using 空间权重矩阵.dta,name(W) standardize
use data反地理矩阵.dta
spatwmat using data反地理矩阵.dta,name(W) standardize
use data.dta
xtset id year
///判断 sdm 会不会退化为sem sar
xsmle y x x2 x5 x6 x8 x9, re model(sar) wmat(W) type(both) nolog noeffects
est store sar
xsmle y x x2 x5 x6 x8 x9, re model(sdm) wmat(W) type(both) nolog noeffects durbin(x)
est store sdm
lrtest sdm sar
xsmle y x x2 x5 x6 x8 x9, re model(sdm) wmat(W) type(both) nolog noeffects
est store both
xsmle y x x2 x5 x6 x8 x9, re model(sdm) wmat(W) type(time) nolog noeffects durbin(x)
est store time
xsmle y x x2 x5 x6 x8 x9, re model(sdm) wmat(W) type(ind) nolog noeffects durbin(x)
est store ind
lrtest both time
lrtest both ind
*回归结果
xsmle y x, re model(sdm) wmat(W) type(both) nolog noeffects
xsmle y x x2 x5 x6 x8 x9, re model(sdm) wmat(W) type(both) nolog effects
est store m1
esttab m1 using regout5.rtf, b(%12.3f) se(%12.3f) nogap compress ///
s(N r2 ar2) star(* 0.1 ** 0.05 *** 0.01)
xsmle y x x2 x5 x6 x8 x9, re model(sdm) wmat(W) type(both) nolog effects
*稳定性
use 空间权重矩阵.dta
spatwmat using 空间权重矩阵.dta,name(W) standardize
use data.dta
xtset id year
xsmle y x x2 x5 x6 x8 x9, re model(sdm) wmat(W) type(both) nolog noeffects
est store m2
xtreg y x x2 x5 x6 x8 x9 i.year,re
est store m3
*xls2dta:import excel data2.xlsx,first case(lower)
use data反地理矩阵.dta
spatwmat using data反地理矩阵.dta,name(W) standardize
use data2.dta
xtset id year
xsmle y x x2 x5 x6 x8 x9, re model(sdm) wmat(W) type(both) nolog effects
est store m4
esttab m2 m3 m4 using regout1.rtf, b(%12.3f) se(%12.3f) nogap compress ///
star(* 0.1 ** 0.05 *** 0.01)
空间计量笔记(代码)
最新推荐文章于 2025-04-29 15:56:44 发布