请选择 进入手机版 | 继续访问电脑版
楼主: jianhui80
28649 70

[区域经济学] matlab运行空间计量操作速成   [推广有奖]

学科带头人

0%

还不是VIP/贵宾

-

威望
1
论坛币
4428 个
通用积分
51.2427
学术水平
89 点
热心指数
97 点
信用等级
67 点
经验
1355 点
帖子
647
精华
1
在线时间
1925 小时
注册时间
2011-7-21
最后登录
2023-4-17

jianhui80 学生认证  发表于 2016-1-15 18:00:24 |显示全部楼层 |坛友微信交流群
相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
目前用matlab做空间计量还处于讳莫如深的境况,很多会操作的人还利用它来赚钱(诸如开培训班等),而不是把相关代码的收集和运算公开,让更多人受益。我觉得这都没有必要,我们做科学研究不是窝里争,再者很多代码是国外学者编的,所以没必要藏着掖着,而是让科学流行起来。在这之前,我公开了R和stata的相关命令和操作,都很受欢迎。基于我的理解和掌握,我决定贡献并适当讲解一下matlab代码,本次分享的代码是:空间面板数据,可能还不是很周全,抛砖引玉吧!如有不懂的地方,请到Regional Study群交流(234081931)。
        
  1. A=xlsread('D:\matlab\toolbox\SpatEcon_ren\Files_SLX_paper\cigarette.xls');
  2. W1=xlsread('D:\matlab\toolbox\SpatEcon_ren\Files_SLX_paper\Spat-Sym-US.xls');
  3. %
  4. % SAR, SEM, SAC, SDM, SDEM and GNS models. Every time this file is run
  5. %
  6. T=30; % number of time periods
  7. N=46; % number of regions
  8. % row-normalize W
  9. W=normw(W1); % function of LeSage
  10. y=A(:,[3]); % column number in the data matrix that corresponds to the dependent variable
  11. x=A(:,[4,6]); % column numbers in the data matrix that correspond to the independent variables
  12. for t=1:T
  13.     t1=(t-1)*N+1;t2=t*N;
  14.     wx(t1:t2,:)=W*x(t1:t2,:);
  15. end
  16. xconstant=ones(N*T,1);
  17. [nobs K]=size(x);           %size返回的是行和列
  18. et=ones(T,1);
  19. en=ones(N,1);
  20. %
  21. % All models include spatial and time period fixed effects
  22. %
  23. % ----------------------------------------------------------------------------------------
  24. % No spatial interaction effects
  25. model=3;
  26. [ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);
  27. results=ols(ywith,xwith);
  28. vnames=strvcat('logcit','logp','logy'); % should be changed if x is changed
  29. prt_reg(results,vnames);
  30. intercept=mean(y)-mean(x)*results.beta;
  31. sfe=meanny-meannx*results.beta-kron(en,intercept);
  32. tfe=meanty-meantx*results.beta-kron(et,intercept);
  33. yme = y - mean(y);
  34. ent=ones(N*T,1);
  35. error=y-kron(tfe,en)-kron(et,sfe)-x*results.beta-kron(ent,intercept);
  36. rsqr1 = error'*error;
  37. rsqr2 = yme'*yme;
  38. FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effects
  39. sige=results.sige*((nobs-K)/nobs);
  40. loglik=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid

  41. % ----------------------------------------------------------------------------------------
  42. % Spatial lag model
  43. info.lflag=0; % required for exact results
  44. info.model=3;
  45. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  46. % New routines to calculate effects estimates
  47. results=sar_panel_FE(y,x,W,T,info);
  48. vnames=strvcat('logcit','logp','logy');
  49. % Print out coefficient estimates
  50. prt_sp(results,vnames,1);
  51. % Print out effects estimates
  52. spat_model=0;
  53. direct_indirect_effects_estimates(results,W,spat_model);
  54. % panel_effects_sar(results,vnames,W);

  55. % ----------------------------------------------------------------------------------------
  56. % Spatial error model
  57. info.lflag=0; % required for exact results
  58. info.model=3;
  59. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  60. % New routines to calculate effects estimates
  61. results=sem_panel_FE(y,x,W,T,info);
  62. % Print out coefficient estimates
  63. prt_sp(results,vnames,1);

  64. % ----------------------------------------------------------------------------------------
  65. % Model with exogenous interaction effects
  66. model=3;
  67. [ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,[x wx],N,T,model);
  68. results=ols(ywith,xwith);
  69. vnames=strvcat('logcit','logp','logy','W*logp','W*logy');
  70. prt_reg(results,vnames);
  71. intercept=mean(y)-mean([x wx])*results.beta;
  72. sfe=meanny-meannx*results.beta-kron(en,intercept);
  73. tfe=meanty-meantx*results.beta-kron(et,intercept);
  74. yme = y - mean(y);
  75. ent=ones(N*T,1);
  76. error=y-kron(tfe,en)-kron(et,sfe)-[x wx]*results.beta-kron(ent,intercept);
  77. rsqr1 = error'*error;
  78. rsqr2 = yme'*yme;
  79. FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effects
  80. sige=results.sige*((nobs-K)/nobs);
  81. loglik=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
  82. % ----------------------------------------------------------------------------------------
  83. % Spatial Durbin model
  84. info.lflag=0; % required for exact results
  85. info.model=3;
  86. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  87. info.bc=1;
  88. % New routines to calculate effects estimates
  89. results=sar_panel_FE(y,[x wx],W,T,info);
  90. % Print out coefficient estimates
  91. prt_sp(results,vnames,1);
  92. % Print out effects estimates
  93. spat_model=1;
  94. direct_indirect_effects_estimates(results,W,spat_model);
  95. %panel_effects_sdm(results,vnames,W);

  96. % ----------------------------------------------------------------------------------------
  97. % Spatial Durbin error model
  98. info.lflag=0; % required for exact results
  99. info.model=3;
  100. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  101. info.bc=1;
  102. % New routines to calculate effects estimates
  103. results=sem_panel_FE(y,[x wx],W,T,info);
  104. % Print out coefficient estimates
  105. prt_sp(results,vnames,1);

  106. % ----------------------------------------------------------------------------------------
  107. % SAC / SARAR / Clifford-Ord/ Kelejian-Prucha model
  108. info.lflag=0; % required for exact results
  109. info.model=3;
  110. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  111. info.bc=1;
  112. results=sac_panel_FE(y,x,W,T,info);
  113. vnames=strvcat('logcit','logp','logy');
  114. prt_spnew(results,vnames,1);
  115. % Print out effects estimates
  116. spat_model=0;
  117. direct_indirect_effects_estimates(results,W,spat_model);
  118. % ----------------------------------------------------------------------------------------
  119. % Full model
  120. info.model=3;
  121. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  122. info.bc=1;
  123. results=sac_panel_FE(y,[x wx],W,T,info);
  124. vnames=strvcat('logcit','logp','logy','W*logp','W*logy');
  125. prt_spnew(results,vnames,1);
  126. % Print out effects estimates
  127. spat_model=1;
  128. direct_indirect_effects_estimates(results,W,spat_model);
复制代码
更多代码信息参见以下网站
Pual Elhost的主页

http://www.regroningen.nl/elhorst/software.shtml
James Lesage 个人主页
http://www.spatial-econometrics.com/
kelley pace个人网站
http://www.spatial-statistics.com/
Donald J. Lacombe个人主页
http://community.wvu.edu/~djlacombe/
Journal of Statistical Software杂志首页
http://www.jstatsoft.org/
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:MATLAB atlab matla 空间计量 Lab matlab 空间

已有 3 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
317792209 + 100 精彩帖子
dalv1990128 + 3 + 1 + 1 + 1 精彩帖子
np84 + 100 精彩帖子

总评分: 经验 + 200  论坛币 + 3  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

本帖被以下文库推荐

区域经济学是经济学中还未开放的花骨朵。
jiankang0501 学生认证  发表于 2016-1-16 09:26:43 |显示全部楼层 |坛友微信交流群
楼主好人!

使用道具

谢谢楼主

使用道具

xiongty 发表于 2016-1-26 22:20:10 |显示全部楼层 |坛友微信交流群
楼主好人,谢谢!

使用道具

flyhkboy 发表于 2016-1-28 12:18:09 |显示全部楼层 |坛友微信交流群
谢谢楼主!

使用道具

无治明界 在职认证  学生认证  发表于 2016-2-14 17:29:48 |显示全部楼层 |坛友微信交流群
为什么加群被拒绝。。。。。

使用道具

天雅尔 学生认证  发表于 2016-3-11 20:41:20 |显示全部楼层 |坛友微信交流群
谢谢楼主  好人

使用道具

jianhui80 学生认证  发表于 2016-3-12 13:22:31 |显示全部楼层 |坛友微信交流群
无治明界 发表于 2016-2-14 17:29
为什么加群被拒绝。。。。。
不是吧,你再加一次。前段时间会员到期,群上限被限制了。

使用道具

sunabinghua 在职认证  学生认证  发表于 2016-4-10 09:42:01 来自手机 |显示全部楼层 |坛友微信交流群
jianhui80 发表于 2016-1-15 18:00
目前用matlab做空间计量还处于讳莫如深的境况,很多会操作的人还利用它来赚钱(诸如开培训班等), ...
感谢楼主分享!

使用道具

liwulin 发表于 2016-4-23 10:24:43 |显示全部楼层 |坛友微信交流群
楼主,操作代码只需要修改自己的文件来源以及变量名就可以使用吗

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-28 23:29