xsmle lny lnx1 lnx2 lnx3 lnx4,fe model(sdm) ///dlag( 2) wmat(matrix1) type(both)nolog effects

*动态空间面板滞后模型xsmle lny lnx1 lnx2 lnx3 lnx4,fe model(sar) ///dlag( 1) wmat(matrix1) type(both)nolog effects

xsmle lny lnx1 lnx2 lnx3 lnx4,fe model(sar) ///dlag( 2) wmat(matrix1) type(both)nolog effects

补充阅读:

一文读懂空间计量及stata应用(附lr检验、空间可视化、权重矩阵、检验、模型dofile等)

转载请注明来源

Tutorial to replicate results of Workshop:

Spatial Econometrics Methods using Stata"

LISER (Luxembourg Institute of Socio-Economic Research)

Luxembourg, 15th February 2017.

Author: Marcos Herrera (CONICET-IELDE, UNSa, Argentina)

e-mail: mherreragomez@gmail.com

主要包括如下内容:

1、空间数据的操作与可视化: 使用地图表示。

2、空间权重矩阵的建立和空间自相关测试:Moran's I test, Geary's c test and Getis-Ord's G test. - LISA: Local Moran's I test.

3、基本空间计量经济学(截面数据):SLM、SEM、SARAR、SDM。

MLE和GMM下的空间参数估计。

测试以确定适当的计量经济设定。

异方差性和内生性校正。

4、高级空间计量经济学:

面板数据中空间效应的介绍,

静态和动态空间面板数据的估计。

1

空间计量经济学命令

需要下载安装外部命令清单如下:

version 14.0*ssc install spmap*ssc install shp2dta*net install sg162, from(http: //www.stata.com/stb/stb60)*net install st0292, from(http: //www.stata-journal.com/software/sj13-2)*net install spwmatrix, from(http: //fmwww.bc.edu/RePEc/bocode/s)*net install splagvar, from(http: //fmwww.bc.edu/RePEc/bocode/s)*ssc install xsmle.pkg*ssc install xtcsd

2

空间数据处理

1、导入数据Read the information shape in Stata

shp2dta using nuts2_164, database(data_shp) coordinates(coord) ///genid(id) genc(c) replace

2、查看数据

usedata_shp, cleardescribe

3、Themeless map (without information)

spmap using coord, id( id) note( "Europe, EU15")

4、If there are some polygons without information: for example, Sweden and Finland

dropifid== 3| id== 5| id== 6| id== 164| id== 7| id== 8| id== 12| id== 4| id== 2| id== 1| id== 11| id== 12spmap usingcoord, id( id) note( "Europe without Finland and Sweden, EU15")

5、 Import from Excel and save in Stata format

clearallimportexcel migr_unemp07_12.xls, firstrowsavemigr_unemp.dta, replaceusemigr_unempdescribe

结果为:

6、 合并数据

usedata_shp, clearmerge1: 1POLY_ID usingmigr_unemp, gen( union) forceassert union== 3

7、 合并数据

dropunionsavemigr_unemp_shp.dta, replace

8、 Showing the informationusingmaps

use migr_unemp_shp.dta

9、 Quantile map:

format U2012 % 12.1fspmap U2012 using coord, id( id) clmethod(q) title( "Unemployment rate") ///legend(size(medium) position( 5)) fcolor(Blues2) note( "Europe, 2012""Source: Eurostat")

format NM2012 % 12.1fspmap NM2012 using coord, id( id) clmethod(q) title( "Net migration rate") ///legend(size(medium) position( 5)) fcolor(BuRd) note( "Europe, 2012""Source: Eurostat")

10、Equal interval maps

spmap U2012 using coord, id( id) clmethod(e) title( "Unemployment rate") ///legend(size(medium) position( 5)) fcolor(Blues2) note( "Europe, 2012""Source: Eurostat")

spmap NM2012 using coord, id( id) clmethod(e) title( "Net migration rate") ///legend(size(medium) position( 5)) fcolor(BuRd) note( "Europe, 2012""Source: Eurostat")

11、 Box maps

spmap U2012 using coord, id( id) clmethod(boxplot) title( "Unemployment rate") ///legend(size(medium) position( 5)) fcolor(Heat) note( "Europe, 2012""Source: Eurostat")spmap NM2012 using coord, id( id) clmethod(boxplot) title( "Net migration rate") ///legend(size(medium) position( 5)) fcolor(Rainbow) note( "Europe, 2012""Source: Eurostat")

graph hbox U2012, asyvars ytitle( "")graph hbox NM2012, asyvars ytitle( "")

12、 Deviation maps

spmap U2012 using coord, id( id) clmethod(s) title( "Unemployment rate") ///legend(size(medium) position( 5)) fcolor(Blues2) note( "Europe, 2012""Source: Eurostat")spmap NM2012 using coord, id( id) clmethod(s) title( "Net migration rate") ///legend(size(medium) position( 5)) fcolor(BuRd) note( "Europe, 2012""Source: Eurostat")

13、 Combination of points and polygons using both variables:

spmap U2012 using coord, id( id) fcolor(RdYlBu) cln( 8) point(data(migr_unemp_shp) xcoord(x_c) ///ycoord(y_c) deviation(NM2012) sh(T) fcolor(dknavy) size(* 0.3)) legend(size(medium) position( 5)) legt(Unemployment) ///note( "Solid triangles indicate values over the mean of net-migration.""Europa, 2012. Source: Eurostat")

spmap NM2012 using coord, id( id) fcolor(RdYlBu) cln( 8) diagram(var(U2012) xcoord(x_c) ycoord(y_c) ///fcolor(gs2) size( 1)) legend(size(medium) position( 5)) legstyle( 3) legt(Net migration) ///note( " ""Boxes indicate values of unemployment.""Europe, 2012. Source: Eurostat")

14、 空间权重矩阵以及空间相关检验

spmat contiguity Wcontig using"coord.dta", id(id)* Problem with conguity criterion: 5islands.* We choose k-nn: 5nearest neighbours row-standardizedspwmatrix gecon y_c x_c, wn(W5st) knn( 5) row con

* We need the spatial W asa SPMAT object:* First, we generate W 5nn binary and then we export astxt

spwmatrix gecon y_c x_c, wn(W5bin) knn( 5) xport(W5bin,txt) replace* Read the txt file and to adapt format forSPMATinsheet using"W5bin.txt", delim( " ") cleardrop in1rename v1 idsave "W5bin.dta", replace* Generate SPMAT object: W5 row-standardizespmat dta W5_st v*, id(id) norm(row)spmat summarize W5_st, linksspmat graph W5_st

15、TIPS FOR MATRICES

1.From .GAL file to Stata format //gal格式导入stata中* spwmatrix import usingmatrix.gal, wname(W_geoda)* 2.From .GWT file to Stata format //gwt格式导入stata中* spmat import W_knn usingknn.gwt, geoda

* 3.From SPMAT objectto SPATWMAT object* spmat export Wknn using"Wknn_noid.txt", noid replace* insheet using"Wknn_noid.txt", delim( " ") clear* drop in1* save "Wknn_noid.dta", replace* spatwmat using"Wcont_noid.dta", name(Wks) standardize

16、空间相关检验

Moran I test, Geary 's c test and Getis-Ord G test.use migr_unemp_shp.dta, clear

spatgsa U2012, w(W5st) moran geary twospatgsa NM2012, w(W5st) moran geary two

17、空间相关检验

* For Getis-Ord test we need a binary matrix:* spatwmat using"W5bin_noid.dta", name(W5b)* This binary matrix has been created previously byspwmatrixspatgsa U2012, w(W5bin) go twospatgsa NM2012, w(W5bin) go two

18、空间相关检验

* Moran I scatterplotsplagvar U2012, wname(W5st) wfrom(Stata) ind(U2012) order( 1) plot(U2012) moran(U2012)splagvar NM2012, wname(W5st) wfrom(Stata) ind(NM2012) order( 1) plot(NM2012) moran(NM2012)* Local Moran I( LISA)genmsp_v0 U2012, w( W5st)graph twoway( scatter Wstd_U2012 std_U2012 ifpval_U2012>= 0.05, msymbol(i) mlabel ///( id) mlabsize( * 0.6) mlabpos( c)) ( scatter Wstd_U2012 std_U2012 ifpval_U2012< 0.05, ///msymbol(i) mlabel( id) mlabsize( * 0.6) mlabpos( c) mlabcol( red)) ( lfit Wstd_U2012 ///std_U2012), yline( 0, lpattern(--)) xline( 0, lpattern(--)) xlabel( -1.5( 1)4.5, ///labsize( * 0.8)) xtitle( "{it:z}") ylabel( -1.5( 1)3.5, angle( 0) labsize( * 0.8)) ///ytitle( "{it:Wz}") legend( off) scheme( s1color) title( "Local Moran I of Unemployment rate")

spmap msp_U2012 usingcoord, id( id) clmethod( unique) title( "Unemployment rate") ///legend( size(medium) position( 4)) ndl( "No signif.") fcolor( blue red) ///note( "Europe, 2012""Source: Eurostat")

19、空间计量分析

OLS estimation************************************************************************************use migr _unemp_shp, clearreg U2012 NM2012

20、空间计量分析

*Spatial testsspwmatrix gecon y _c x_c, wn(W5st) knn(5) rowspatdiag, weights(W5st)

21、空间计量分析

*************************************************************************************Spatial models using Maximum Likelihood (ML)*************************************************************************************Spatial Lag Model (SLM) with W5_st spmat objectspreg ml U2012 NM2012, id(id) dlmat(W5_st)estimates store SLM_ml*Spatial Error Model (SEM)spreg ml U2012 NM2012, id(id) elmat(W5_st)estimates store SEM_ml

*Spatial autoregressive SARAR model: combine SLM-SEMspreg ml U2012 NM2012, id(id) dlmat(W5 _st) elmat(W5_st)estimates store SARAR_ml

*Spatial Durbin model (SDM)spmat lag wx _NM2012 W5_st NM2012

spreg ml U2012 NM2012 wx _NM2012, id(id) dlmat(W5_st)estimates store SDM_ml

22、LR检验,SEM模型与SDM模型

*Selecting between SDM and SEM: LR_comfaclrtest SDM _ml SEM_mlestimates table SLM _ml SEM_ml SARAR _ml SDM_ml CLIFFORD_ml, b(%7.2f) star(0.1 0.05 0.01)*Others alternative commands: "spmlreg" de Jeanty o "spatreg" de Pisati

23、空间计量分析

*************************************************************************************Spatial model using Instrumental Variables / Generalized method of moments(IV-GMM)*************************************************************************************Spatial Lag Model (SLM)spivreg U2012 NM2012, dl(W5_st) id(id)

*SLM could be estimated using habitual commands in Stataspmat lag wx _U2012 W5_st U2012spmat lag wx2 _NM2012 W5_st wx_NM2012ivregress 2sls U2012 NM2012 (wx _U2012 = wx_NM2012 wx2_NM2012)

*Spatial Error Model (SEM)spivreg U2012 NM2012, el(W5_st) id(id)

*SARAR Modelspivreg U2012 NM2012, dl(W5 _st) el(W5_st) id(id)

*Spatial Durbin Model (SDM)spivreg U2012 NM2012 wx _NM2012, dl(W5_st) id(id)ereturn list*Same result of SDM using ivregress:spmat lag wx3 _NM2012 W5_st wx2_NM2012ivregress 2sls U2012 NM2012 wx _NM2012 (wx_U2012 = wx2 _NM2012 wx3_NM2012)

*Cliff-Ord Modelspivreg U2012 NM2012 wx _NM2012, dl(W5_st) el(W5_st) id(id)

*************************************************************************************Corrections for heteroskedasticity and endogeneity

*SLM assuming endogeneity in net migration and heteroskedasticityspivreg U2012 NM2012 (NM2012 = NM2009), dl(W5_st) id(id) het

*SEM assuming endogeneity in net migration and heteroskedasticityspivreg U2012 NM2012 (NM2012 = NM2009), el(W5_st) id(id) het

*SARAR with heteroskedasticity correctionspivreg U2012 NM2012, el(W5 _st) dl(W5_st) id(id) het

*Alternative command: "spreg gs2sls"

*************************************************************************************Interpretation of spatial estimation************************************************************************************

*Remembering the SLM estimated under MLuse migr _unemp_shp, clearspreg ml U2012 NM2012, dl(W5_st) id(id)

*Read W and betas in MATA languagespmat getmatrix W5_st Wmata:b = st_matrix("e(b)")blambda = b[1,3]lambdaS = luinv(I(rows(W))-lambda*W)end

*Using formulas of effects

*Total effectsmata: (b[1,1]/rows(W))*sum(S)

*Direct effectsmata: (b[1,1]/rows(W))*trace(S)

*Indirect effects (spatial spillovers)mata: (b[1,1]/rows(W)) *sum(S) - (b[1,1]/rows(W))*trace(S)

24、高级空间计量分析

*Reshaping format: from wide to long formatreshape long NM U, i(id) j(year)tsset id yearxtset id yearxtdes

*************************************************************************************STATIC MODELS************************************************************************************

*************************************************************************************Spatial deteccionxtreg U NM, fextcsd, pes abs

xtreg U NM, rextcsd, pes abs

*Fixed Effects

*SLM modelxsmle U NM, fe wmat(W5_st) mod(sar) hausmanxsmle U NM, fe type(ind, leeyu) wmat(W5_st) mod(sar) effectsestimates store SLM_fe

*SEM modelxsmle U NM, fe emat(W5_st) mod(sem) hausmanestimates store SEM_fe

*SARAR modelxsmle U NM, fe wmat(W5 _st) emat(W5_st) mod(sac) effectsestimates store SARAR_fe

*SDM modelxsmle U NM, fe type(ind) wmat(W5_st) mod(sdm) hausman effectsestimates store SDM_fe*Common factor Testtestnl ([Wx]NM = -[Spatial]rho*[Main]NM)

estimates table SLM _fe SEM_fe SARAR _fe SDM_fe, b(%7.2f) star(0.1 0.05 0.01) statistics(aic)

*Random Effects

*SLM modelxsmle U NM, wmat(W5_st) mod(sar)*SEM modelxsmle U NM, emat(W5_st) mod(sem)*SDM modelxsmle U NM, wmat(W5_st) mod(sdm)

*************************************************************************************DYNAMIC MODELS************************************************************************************

*************************************************************************************Detecting serial dependencextserial U NM

*dynSLM model (named as SAR)xsmle U NM, dlag(1) fe wmat(W5_st) type(ind) mod(sar) effects nsim(499)estimates store dynSLM_1xsmle U NM, dlag(2) fe wmat(W5_st) type(ind) mod(sar) effects nsim(499)estimates store dynSLM_2xsmle U NM, dlag(3) fe wmat(W5_st) type(ind) mod(sar) effects nsim(499)estimates store dynSLM_3estimates table dynSLM _1 dynSLM_2 dynSLM_3, b(%7.2f) star(0.1 0.05 0.01) statistics(aic)

*dynSDM model*xsmle U NM, dlag(1) fe wmat(W5_st) type(ind) mod(sdm) effects nsim(499)*estimates store dynSDM_1*xsmle U NM, dlag(2) fe wmat(W5_st) type(ind) mod(sdm) effects*estimates store dynSDM_2*xsmle U NM, dlag(3) fe wmat(W5_st) type(ind) mod(sdm) effects*estimates store dynSDM_3返回搜狐,查看更多

stata 空间杜宾模型_一文读懂空间计量及stata应用(二)(附lr检验、动态空间面板杜宾/滞后模型dofile等)...相关推荐

  1. matlab运行stata命令,一文读懂108个常用stata命令

    原标题:一文读懂108个常用stata命令 本文由计量经济学服务中心编辑整理,转载请注明出处.下面命令按照重要程度以及相关分析方法步骤等依次列出. Some useful Stata commands ...

  2. stata 将数据集变量名称导出_一文读懂空间计量经济学及stata操作

    在Stata 15中,推出了最新的空间计量官方命令,均以sp开头,表示 spatial data),可以处理横截面与面板形式的空间数据.本文主要为大家介绍空间计量命令之spregress的使用. 一. ...

  3. stata 求输出相关系数矩阵命令_一文读懂结果输出命令大全(上)

    目录 描述统计量 help tabstat   //Stata 官方命令 描述统计量组间均值差异检验 help ttest help ttable2 help estout 相关分析命令 help p ...

  4. psm倾向得分匹配法举例_一文读懂倾向得分匹配法(PSM)举例及stata实现(一)

    原标题:一文读懂倾向得分匹配法(PSM)举例及stata实现(一) 一.倾向匹配得分应用之培训对工资的效应 政策背景:国家支持工作示范项目( National Supported Work,NSW ) ...

  5. gps导航原理与应用_一文读懂角速度传感器(陀螺仪)的应用场景

    前文我们大致了解陀螺仪的来历,原理和种类,那么,它与我们的日常生活有怎样的关系呢? 陀螺仪器最早是用于航海导航,但随着科学技术的发展,它在航空和航天事业中也得到广泛的应用.陀螺仪器不仅可以作为指示仪表 ...

  6. hdfs读写流程_一文读懂HDFS分布式存储框架分析

    一文读懂HDFS分布式存储框架分析 HDFS是一套基于区块链技术的个人的数据存储系统,利用无处不在的私人PC存储空间及便捷的网络为个人提供数据加密存储服务,将闲置的存储空间利用起来,服务于正处于爆发期 ...

  7. mysql 默认事务隔离级别_一文读懂MySQL的事务隔离级别及MVCC机制

    回顾前文: <一文学会MySQL的explain工具> <一文读懂MySQL的索引结构及查询优化> (同时再次强调,这几篇关于MySQL的探究都是基于5.7版本,相关总结与结论 ...

  8. 三轴加速度传感器和六轴惯性传感器_一文读懂三轴,六轴,MEMS陀螺仪(角速率传感器)的区别...

    原标题:一文读懂三轴,六轴,MEMS陀螺仪(角速率传感器)的区别 随着现代科技的不断发展,陀螺仪也被应用到越来越多的领域和行业,例如我们常见纸飞机等飞行类游戏,赛车类游戏等.以陀螺仪为核心的惯性制导系 ...

  9. java中date类型如何赋值_一文读懂java中的Reference和引用类型

    简介 java中有值类型也有引用类型,引用类型一般是针对于java中对象来说的,今天介绍一下java中的引用类型.java为引用类型专门定义了一个类叫做Reference.Reference是跟jav ...

  10. python输入什么就输出什么_一文读懂Python的输入和输出

    本文介绍了Python的输入和输出,既然是Python代码,那么就一定有输出量,那么,Python是如何输出的呢? 输出 用print()在括号中加上字符串,就可以向屏幕上输出指定的文字.比如输出'h ...

最新文章

  1. 算法工程师当前选哪个方向好?
  2. vs 常见问题汇总
  3. 松哥整理了 15 道 Spring Boot 高频面试题,看完当面霸
  4. vue index.php,如何解决vue $index报错问题
  5. pdfplumber解析pdf文件
  6. xml转java代码_java 中xml转换为Bean实例解析(纯代码)
  7. oracle11g ADR 位置
  8. 【报错】android.database.sqlite.SQLiteException: no such column: id (code 1): , while compiling: select
  9. linux定时删除文件,Linux下定时删除文件
  10. python异步调用exe等待_【Python】Async异步等待简单例子理解
  11. java计算机二级内容总结
  12. pxe(hanewin)安装ubuntu-七侠镇莫小贝
  13. 计算机课开机心得学生,计算机课学习心得范文体会范文(精选8篇)
  14. Windows 开启护眼模式 | Windows护眼软件
  15. 系统架构设计笔记(74)—— 企业信息化与电子商务
  16. 图书信息管理系统(一)
  17. 典型相关分析如何分析两组变量的关系
  18. 参考文献格式字号字体_实用文档其他之参考文献的正确格式要求参考文献字体格式要求...
  19. Vue +TS 找不到模块 或 其相应的类型声明
  20. 抖音禁封规则讲解(8)涉嫌黑社会,走私物品被禁封丨国仁网络

热门文章

  1. 关于集异璧实验室(Geblab)
  2. Android学习资料整理:流行框架网站书籍推荐---博客推荐
  3. 数值方法:多项式插值
  4. 微软服务器补丁每月几号发布,微软补丁日安全通告 |9 月份
  5. 实验第七节——用户chaincode相关操作
  6. JAVA学习笔记:目录
  7. FleaPHP 1.0.70 开发进度汇报专贴
  8. IntelliJ IDEA安卓开发环境搭建
  9. Linux/windows下java调用lingo
  10. 20篇聊天机器人领域必读论文速递!