(完整版)六步学会用MATLAB做空间计量回归详细步骤知识讲解_第1页
(完整版)六步学会用MATLAB做空间计量回归详细步骤知识讲解_第2页
(完整版)六步学会用MATLAB做空间计量回归详细步骤知识讲解_第3页
(完整版)六步学会用MATLAB做空间计量回归详细步骤知识讲解_第4页
(完整版)六步学会用MATLAB做空间计量回归详细步骤知识讲解_第5页
已阅读5页,还剩36页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -六 步 学 会 用 MATL AB做 空 间 计 量 回 归 详 细步 骤- - -细心整理 - - - 欢迎下载 - - -第 1 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料1. excel与 MATLAB链接:Excel:选项 加载项 COM 加载项转到没有勾选项2. MATLAB 安装目录中查找toolbox exlink点击 ,启用宏E:MATLABtoolboxexlink然后, Excel 中就显现 MAT

2、LAB工具(留意 Excel 中的数据:)精品资料- - -细心整理 - - - 欢迎下载 - - -第 2 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料3. 启动 matlab(1) )点击 start MATLAB(2) )senddatatomatlab,并对变量矩阵变量进行命名(留意:选取变量为数 值,不包括各变量)data表中数据进行命名 精品资料- - -细心整理 - - - 欢迎下载 - - -第 3 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - -

3、 - - -学习 好资料(空间权重进行命名)(3) )导入 MATLAB 中的两个矩阵变量就可以观察4. 将 elhorst和 jplv7两个程序文件夹复制到MATLAB安装目录的 toolbox文件夹5.设置路径:精品资料- - -细心整理 - - - 欢迎下载 - - -第 4 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料6.输入程序,得出结果T=30; N=46;精品资料- - -细心整理 - - - 欢迎下载 - - -第 5 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - -

4、 - - - - - - - -学习 好资料W=normwW1; y=A:,3; x=A:,4,6;xconstant=onesN*T,1; nobs K=sizex; results=olsy,xconstant x;vnames=strvcat'logcit' ,'intercept','logp','logy' prt_regresults,vnames,1; sige=results.sige*nobs-K/nobs;loglikols=-nobs/2*log2*pi*sige-1/2*sige*results.resid

5、'*results.resid% The robustLM tests developed by Elhorst LMsarsem_panelresults,W,y,xconstant x; % Robust LM tests说明每一行分别表示:该面板数据的时期数为30( T=30),该面板数据有 30 个地区( N=30),将空间权重矩阵标准化(W=normww1 ),将名为 A (以矩阵形式显现在MATLABA中)的变量的第3 列数据定义为被说明变量 y,将名为 A 的变量的第 4、5、6 列数据定义为说明变量矩阵x,定义一个有 N*T 行, 1 列的全 1 矩阵,该矩阵名为: x

6、constant,( ones即为全 1 矩阵)说明说明变量矩阵x 的大小:有 nobs行, K 列;( size 为描述矩阵的大小);附录:精品资料- - -细心整理 - - - 欢迎下载 - - -第 6 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料静态面板空间计量经济学一、OLS 静态面板编程 1、一般面板编程T=30;N=46;W=normwW1; y=A:,3; x=A:,4,6;xconstant=onesN*T,1; nobs K=sizex; results=olsy,xconstant x;vna

7、mes=strvcat'logcit' ,'intercept','logp','logy'prt_regresults,vnames,1; sige=results.sige*nobs-K/nobs;loglikols=-nobs/2*log2*pi*sige-1/2*sige*results.resid'*results.resid% The robustLM tests developed by Elhorst LMsarsem_panelresults,W,y,xconstant x; % Robust LM te

8、sts2、空间固定 OLS ( spatial-fixed effects) T=30;N=46;精品资料- - -细心整理 - - - 欢迎下载 - - -第 7 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料W=normwW1; y=A:,3; x=A:,4,6;xconstant=onesN*T,1; nobs K=sizex; model=1;ywith,xwith,meanny,meannx,meanty,meantx=demeany,x,N,T,model; results=olsywith,xwith;

9、vnames=strvcat'logcit','logp','logy' % should be changed if x is changed prt_regresults,vnames;sfe=meanny-meannx*results.beta; % including the constant term yme = y - meany;et=onesT,1;error=y-kronet,sfe-x*results.beta; rsqr1 = error'*error;rsqr2 = yme'*yme;FE_rsqr2 =

10、1.0 - rsqr1/rsqr2 % r-squared including fixed effects sige=results.sige*nobs-K/nobs;logliksfe=-nobs/2*log2*pi*sige-1/2*sige*results.resid'*results.resid LMsarsem_panelresults,W,ywith,xwith; % Robust LM tests3、时期固定 OLS(time-period fixed effects)精品资料- - -细心整理 - - - 欢迎下载 - - -第 8 页,共 23 页精品word学习资料

11、 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料T=30; N=46;W=normwW1; y=A:,3; x=A:,4,6;xconstant=onesN*T,1;nobs K=sizex; model=2;ywith,xwith,meanny,meannx,meanty,meantx=demeany,x,N,T,model; results=olsywith,xwith;vnames=strvcat'logcit','logp','logy' % should be changed if x is ch

12、anged prt_regresults,vnames;tfe=meanty-meantx*results.beta; % including the constant term yme = y - meany;en=onesN,1;error=y-krontfe,en-x*results.beta; rsqr1 = error'*error;rsqr2 = yme'*yme;FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effects sige=results.sige*nobs-K/nobs;loglikt

13、fe=-nobs/2*log2*pi*sige-1/2*sige*results.resid'*results.resid LMsarsem_panelresults,W,ywith,xwith; % Robust LM tests精品资料- - -细心整理 - - - 欢迎下载 - - -第 9 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料4、空间与时间双固定模型T=30; N=46;W=normwW1; y=A:,3; x=A:,4,6;xconstant=onesN*T,1; nobs K=sizex

14、; model=3;ywith,xwith,meanny,meannx,meanty,meantx=demeany,x,N,T,model;results=olsywith,xwith;vnames=strvcat'logcit','logp','logy' % should be changed if x is changed prt_regresults,vnamesen=onesN,1;et=onesT,1;intercept=meany-meanx*results.beta; sfe=meanny-meannx*results.beta-

15、kronen,intercept; tfe=meanty-meantx*results.beta-kronet,intercept; yme = y - meany;ent=onesN*T,1;error=y-krontfe,en-kronet,sfe-x*results.beta-kronent,intercept;精品资料- - -细心整理 - - - 欢迎下载 - - -第 10 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料rsqr1 = error'*error; rsqr2 = yme'*

16、yme;FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effects sige=results.sige*nobs-K/nobs;loglikstfe=-nobs/2*log2*pi*sige-1/2*sige*results.resid'*results.resid LMsarsem_panelresults,W,ywith,xwith; % Robust LM tests二、静态面板 SAR 模型1、无固定效应( No fixed effects)T=30; N=46;W=normwW1; y=A:,3;x=A:,

17、4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;endxconstant=onesN*T,1; nobs K=sizex; info.lflag=0; info.model=0;info.fe=0;results=sar_panel_FEy,xconstant x,W,T,info;vnames=strvcat'logcit', 'intercept', 'logp', 'logy' prt_spnewresults,vnames,1% Print out effects e

18、stimates spat_model=0;direct_indirect_effects_estimatesresults,W,spat_model;panel_effects_sarresults,vnames,W;2、空间固定效应( Spatial fixed effects)T=30; N=46;精品资料- - -细心整理 - - - 欢迎下载 - - -第 11 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料W=normwW1; y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t

19、*N; wxt1:t2,:=W*xt1:t2,:;endxconstant=onesN*T,1; nobs K=sizex; info.lflag=0; info.model=1;info.fe=0; results=sar_panel_FEy,x,W,T,info;vnames=strvcat'logcit', 'logp', 'logy'prt_spnewresults,vnames,1% Print out effects estimates spat_model=0;direct_indirect_effects_estimatesres

20、ults,W,spat_model;panel_effects_sarresults,vnames,W;3、时点固定效应( Time period fixed effects)T=30; N=46;W=normwW1; y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;end xconstant=onesN*T,1; nobs K=sizex;info.lflag=0;% required for exact results info.model=2;info.fe=0;% Do not print intercep

21、t and fixed effects; use info.fe=1 to turn onresults=sar_panel_FEy,x,W,T,info;vnames=strvcat'logcit', 'logp', 'logy' prt_spnewresults,vnames,1% Print out effects estimates spat_model=0;direct_indirect_effects_estimatesresults,W,spat_model;精品资料- - -细心整理 - - - 欢迎下载 - - -第 12 页,

22、共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料panel_effects_sarresults,vnames,W;4、双固定效应( Spatial and time period fixed effects)T=30; N=46;W=normwW1; y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;endxconstant=onesN*T,1; nobs K=sizex;info.lflag=0;% required for exact re

23、sults info.model=3;info.fe=0;% Do not print intercept and fixed effects; use info.fe=1to turn on results=sar_panel_FEy,x,W,T,info;vnames=strvcat'logcit', 'logp', 'logy' prt_spnewresults,vnames,1% Print out effects estimatesspat_model=0; direct_indirect_effects_estimatesresult

24、s,W,spat_model; panel_effects_sarresults,vnames,W;三、静态面板 SDM 模型1、无固定效应( No fixed effects)T=30; N=46;W=normwW1;y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;end xconstant=onesN*T,1; nobs K=sizex; info.lflag=0; info.model=0;精品资料- - -细心整理 - - - 欢迎下载 - - -第 13 页,共 23 页精品word学习资料 可编辑资料

25、- - - - - - - - - - - - - - - -学习 好资料info.fe=0;results=sar_panel_FEy,xconstant x wx,W,T,info;vnames=strvcat'logcit', 'intercept', 'logp', 'logy', 'W*logp', 'W*logy' prt_spnewresults,vnames,1% Print out effects estimates spat_model=1;direct_indirect_eff

26、ects_estimatesresults,W,spat_model;panel_effects_sdmresults,vnames,W;2、空间固定效应( Spatial fixed effects)T=30; N=46;W=normwW1; y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;endxconstant=onesN*T,1; nobs K=sizex;info.lflag=0;% required for exact resultsinfo.model=1;info.fe=0;% Do not pri

27、nt intercept and fixed effects; use info.fe=1 to turn onresults=sar_panel_FEy,x wx,W,T,info;vnames=strvcat'logcit', 'logp', 'logy', 'W*logp', 'W*logy' prt_spnewresults,vnames,1% Print out effects estimatesspat_model=1; direct_indirect_effects_estimatesresults,

28、W,spat_model; panel_effects_sdmresults,vnames,W;3、时点固定效应( Time period fixed effects)T=30; N=46;W=normwW1;y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;end xconstant=onesN*T,1;精品资料- - -细心整理 - - - 欢迎下载 - - -第 14 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料nobs K=siz

29、ex;info.lflag=0;% required for exact results info.model=2;info.fe=0;% Do not print intercept and fixed effects; use info.fe=1to turn on% New routines to calculate effects estimates results=sar_panel_FEy,x wx,W,T,info;vnames=strvcat'logcit', 'logp', 'logy', 'W*logp', &

30、#39;W*logy'% Print out coefficient estimates prt_spnewresults,vnames,1% Print out effects estimates spat_model=1;direct_indirect_effects_estimatesresults,W,spat_model; panel_effects_sdmresults,vnames,W4、双固定效应( Spatial and time period fixed effects)T=30; N=46;W=normwW1;y=A:,3;x=A:,4,6;fort=1:Tt1=

31、t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;end xconstant=onesN*T,1; nobs K=sizex; info.bc=0;info.lflag=0;% required for exact resultsinfo.model=3;info.fe=0;% Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sar_panel_FEy,x wx,W,T,info;vnames=strvcat'logcit', 'logp'

32、, 'logy', 'W*logp', 'W*logy' prt_spnewresults,vnames,1% Print out effects estimates spat_model=1;direct_indirect_effects_estimatesresults,W,spat_model; panel_effects_sdmresults,vnames,Wwald test spatial lag% Wald test for spatial Durbin model against spatial lag model精品资料- -

33、-细心整理 - - - 欢迎下载 - - -第 15 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料btemp=results.parm; varcov=results.cov; Rafg=zerosK,2*K+2; fork=1:KRafgk,K+k=1;% R1,3=0 and R2,4=0;end Wald_spatial_lag=Rafg*btemp'*invRafg*varcov*Rafg'*Rafg*btemp prob_spatial_lag=1-chis_cdf Wald_spatia

34、l_lag, Kwald test spatial error% Wald test spatial Durbin model against spatial error model R=zerosK,1;fork=1:KRk=btemp2*K+1*btempk+btempK+k;% k changed in 1, 7/12/2021%R1=btemp5*btemp1+btemp3;%R2=btemp5*btemp2+btemp4; endRafg=zerosK,2*K+2; fork=1:KRafgk,k=btemp2*K+1;% k changed in 1, 7/12/2021 Rafg

35、k,K+k =1;Rafgk,2*K+1=btempk;%Rafg1,1=btemp5;Rafg1,3=1;Rafg1,5=btemp1;%Rafg2,2=btemp5;Rafg2,4=1;Rafg2,5=btemp2; endWald_spatial_error=R'*invRafg*varcov*Rafg'*Rprob_spatial_error=1-chis_cdf Wald_spatial_error,KLR test spatial lagresultssar=sar_panel_FEy,x,W,T,info; LR_spatial_lag=-2*resultssar

36、.lik-results.lik prob_spatial_lag=1-chis_cdf LR_spatial_lag,KLR test spatial errorresultssem=sem_panel_FEy,x,W,T,info; LR_spatial_error=-2*resultssem.lik-results.lik prob_spatial_error=1-chis_cdf LR_spatial_error,K精品资料- - -细心整理 - - - 欢迎下载 - - -第 16 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - -

37、- - -学习 好资料5、空间随机效应与时点固定效应模型T=30; N=46;W=normwW1;y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;end xconstant=onesN*T,1; nobs K=sizex;ywith,xwith,meanny,meannx,meanty,meantx=demeany,x wx,N,T,2;% 2=time dummiesinfo.model=1; results=sar_panel_REywith,xwith,W,T,info; prt_spnewresults,v

38、names,1spat_model=1; direct_indirect_effects_estimatesresults,W,spat_model; panel_effects_sdmresults,vnames,Wwald test spatial lagbtemp=results.parm1:2*K+2; varcov=results.cov1:2*K+2,1:2*K+2; Rafg=zerosK,2*K+2;fork=1:KRafgk,K+k=1;% R1,3=0 and R2,4=0;end Wald_spatial_lag=Rafg*btemp'*invRafg*varco

39、v*Rafg'*Rafg*btemp prob_spatial_lag= 1-chis_cdf Wald_spatial_lag, Kwald test spatial errorR=zerosK,1; fork=1:KRk=btemp2*K+1*btempk+btempK+k;% k changed in 1, 7/12/2021精品资料- - -细心整理 - - - 欢迎下载 - - -第 17 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料%R1=btemp5*btemp1+btemp3;%R2=bte

40、mp5*btemp2+btemp4; endRafg=zerosK,2*K+2;fork=1:KRafgk,k=btemp2*K+1;% k changed in 1, 7/12/2021 Rafgk,K+k =1;Rafgk,2*K+1=btempk;%Rafg1,1=btemp5;Rafg1,3=1;Rafg1,5=btemp1;%Rafg2,2=btemp5;Rafg2,4=1;Rafg2,5=btemp2; endWald_spatial_error=R'*invRafg*varcov*Rafg'*Rprob_spatial_error= 1-chis_cdf Wald

41、_spatial_error,KLR test spatial lagresultssar=sar_panel_REywith,xwith:,1:K,W,T,info; LR_spatial_lag=-2*resultssar.lik-results.lik prob_spatial_lag=1-chis_cdf LR_spatial_lag,KLR test spatial errorresultssem=sem_panel_REywith,xwith:,1:K,W,T,info; LR_spatial_error=-2*resultssem.lik-results.lik prob_spa

42、tial_error=1-chis_cdf LR_spatial_error,K四、静态面板 SEM 模型1、无固定效应( No fixed effects)T=30; N=46;W=normwW1; y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;endxconstant=onesN*T,1; nobs K=sizex;精品资料- - -细心整理 - - - 欢迎下载 - - -第 18 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料i

43、nfo.lflag=0; info.model=0; info.fe=0;results=sem_panel_FEy,xconstant x,W,T,info;vnames=strvcat'logcit', 'intercept', 'logp', 'logy' prt_spnewresults,vnames,1% Print out effects estimatesspat_model=0; direct_indirect_effects_estimatesresults,W,spat_model; panel_effects

44、_sarresults,vnames,W;2、空间固定效应( Spatial fixed effects)T=30; N=46;W=normwW1; y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;end xconstant=onesN*T,1; nobs K=sizex; info.lflag=0; info.model=1;info.fe=0; results=sem_panel_FEy,x,W,T,info;vnames=strvcat'logcit', 'logp', 

45、9;logy' prt_spnewresults,vnames,1% Print out effects estimates spat_model=0;direct_indirect_effects_estimatesresults,W,spat_model;panel_effects_sarresults,vnames,W;3、时点固定效应( Time period fixed effects)T=30; N=46;W=normwW1; y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;end精品资料- -

46、 -细心整理 - - - 欢迎下载 - - -第 19 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -学习 好资料xconstant=onesN*T,1; nobs K=sizex;info.lflag=0;% required for exact results info.model=2;info.fe=0;% Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sem_panel_FEy,x,W,T,info;vnames=str

47、vcat'logcit', 'logp', 'logy' prt_spnewresults,vnames,1% Print out effects estimates spat_model=0;direct_indirect_effects_estimatesresults,W,spat_model;panel_effects_sarresults,vnames,W;4、双固定效应( Spatial and time period fixed effects)T=30; N=46;W=normwW1; y=A:,3;x=A:,4,6;fort=1

48、:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;endxconstant=onesN*T,1; nobs K=sizex;info.lflag=0;% required for exact resultsinfo.model=3;info.fe=0;% Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sem_panel_FEy,x,W,T,info;vnames=strvcat'logcit', 'logp', 'log

49、y' prt_spnewresults,vnames,1% Print out effects estimatesspat_model=0; direct_indirect_effects_estimatesresults,W,spat_model; panel_effects_sarresults,vnames,W;五、静态面板 SDEM 模型1、无固定效应( No fixed effects)T=30;精品资料- - -细心整理 - - - 欢迎下载 - - -第 20 页,共 23 页精品word学习资料 可编辑资料 - - - - - - - - - - - - - - - -

50、学习 好资料N=46;W=normwW1; y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;end xconstant=onesN*T,1; nobs K=sizex; info.lflag=0; info.model=0;info.fe=0;results=sem_panel_FEy,xconstant x wx,W,T,info;vnames=strvcat'logcit', 'intercept', 'logp', 'logy', 'W*

51、logp', 'W*logy' prt_spnewresults,vnames,1% Print out effects estimatesspat_model=1; direct_indirect_effects_estimatesresults,W,spat_model; panel_effects_sdmresults,vnames,W;2、空间固定效应( Spatial fixed effects)T=30; N=46;W=normwW1; y=A:,3;x=A:,4,6;fort=1:Tt1=t-1*N+1;t2=t*N; wxt1:t2,:=W*xt1:t2,:;e

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论