版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、六步学会用matlab做空间计量回归详细步骤六步学会用matlab做空间计量回归详细步骤 编辑整理:尊敬的读者朋友们:这里是精品文档编辑中心,本文档内容是由我和我的同事精心编辑整理后发布的,发布之前我们对文中内容进行仔细校对,但是难免会有疏漏的地方,但是任然希望(六步学会用matlab做空间计量回归详细步骤)的内容能够给您的工作和学习带来便利。同时也真诚的希望收到您的建议和反馈,这将是我们进步的源泉,前进的动力。本文可编辑可修改,如果觉得对您有帮助请收藏以便随时查阅,最后祝您生活愉快 业绩进步,以下为六步学会用matlab做空间计量回归详细步骤的全部内容。文案大全1。excel与matlab链
2、接:excel:选项加载项-com加载项转到没有勾选项 2。 matlab安装目录中寻找toolbox-exlink-点击,启用宏 e:matlabtoolboxexlink然后,excel中就出现matlab工具(注意excel中的数据:)3。启动matlab(1) 点击start matlab(2) senddata to matlab ,并对变量矩阵变量进行命名(注意:选取变量为数值,不包括各变量)(data表中数据进行命名)(空间权重进行命名)(3) 导入matlab中的两个矩阵变量就可以看见4。将elhorst和jplv7两个程序文件夹复制到matlab安装目录的toolbox文件夹
3、5。设置路径:6。输入程序,得出结果t=30; n=46; w=normw(w1); y=a(:,3); x=a(:,4,6); xconstant=ones(nt,1);nobs k=size(x);results=ols(y,xconstant x);vnames=strvcat(logcit,intercept,logp,logy);prt_reg(results,vnames,1);sige=results。sige(nobs-k)/nobs);loglikols=nobs/2*log(2pi*sige)-1/(2*sige)results.resid*results.resid th
4、e (robust)lm tests developed by elhorstlmsarsem_panel(results,w,y,xconstant x); % (robust) lm tests解释每一行分别表示:该面板数据的时期数为30(t=30),该面板数据有30个地区(n=30),将空间权重矩阵标准化(w=normw(w1)),将名为a(以矩阵形式出现在matlaba中)的变量的第3列数据定义为被解释变量y,将名为a的变量的第4、5、6列数据定义为解释变量矩阵x,定义一个有n*t行,1列的全1矩阵,该矩阵名为:xconstant,(ones即为全1矩阵)说明解释变量矩阵x的大小:有n
5、obs行,k列。(size为描述矩阵的大小)。附录:静态面板空间计量经济学一、ols静态面板编程1、普通面板编程t=30; n=46; w=normw(w1); y=a(:,3); x=a(:,4,6); xconstant=ones(nt,1);nobs k=size(x);results=ols(y,xconstant x);vnames=strvcat(logcit,intercept,logp,logy);prt_reg(results,vnames,1);sige=results。sige*(nobsk)/nobs);loglikols=nobs/2*log(2pi*sige)-1/
6、(2*sige)results。resid*results.resid the (robust)lm tests developed by elhorstlmsarsem_panel(results,w,y,xconstant x); % (robust) lm tests2、空间固定ols (spatialfixed effects)t=30; n=46; w=normw(w1); y=a(:,3); x=a(:,4,6); xconstant=ones(n*t,1);nobs k=size(x);model=1;ywith,xwith,meanny,meannx,meanty,meantx
7、=demean(y,x,n,t,model);results=ols(ywith,xwith);vnames=strvcat(logcit,logp,logy); should be changed if x is changedprt_reg(results,vnames);sfe=meanny-meannxresults.beta; % including the constant termyme = y mean(y);et=ones(t,1);error=ykron(et,sfe)xresults.beta;rsqr1 = errorerror;rsqr2 = ymeyme;fe_rs
8、qr2 = 1。0 rsqr1/rsqr2 r-squared including fixed effectssige=results.sige*((nobs-k)/nobs);logliksfe=nobs/2*log(2*pisige)1/(2sige)*results。resid*results.residlmsarsem_panel(results,w,ywith,xwith); (robust) lm tests3、时期固定ols(timeperiod fixed effects)t=30; n=46; w=normw(w1); y=a(:,3); x=a(:,4,6); xconst
9、ant=ones(nt,1);nobs k=size(x);model=2;ywith,xwith,meanny,meannx,meanty,meantx=demean(y,x,n,t,model);results=ols(ywith,xwith);vnames=strvcat(logcit,logp,logy); % should be changed if x is changedprt_reg(results,vnames);tfe=meanty-meantx*results.beta; % including the constant termyme = y mean(y);en=on
10、es(n,1);error=ykron(tfe,en)-x*results。beta;rsqr1 = error*error;rsqr2 = ymeyme;fe_rsqr2 = 1.0 - rsqr1/rsqr2 % rsquared including fixed effectssige=results.sige*(nobs-k)/nobs);logliktfe=nobs/2log(2pisige)1/(2sige)results。residresults.residlmsarsem_panel(results,w,ywith,xwith); (robust) lm tests4、空间与时间
11、双固定模型t=30; n=46; w=normw(w1); y=a(:,3); x=a(:,4,6); xconstant=ones(n*t,1);nobs k=size(x);model=3;ywith,xwith,meanny,meannx,meanty,meantx=demean(y,x,n,t,model);results=ols(ywith,xwith);vnames=strvcat(logcit,logp,logy); % should be changed if x is changedprt_reg(results,vnames)en=ones(n,1);et=ones(t,1
12、);intercept=mean(y)mean(x)*results.beta; sfe=meanny-meannx*results。beta-kron(en,intercept);tfe=meanty-meantx*results。beta-kron(et,intercept);yme = y mean(y);ent=ones(nt,1);error=y-kron(tfe,en)kron(et,sfe)-xresults.betakron(ent,intercept);rsqr1 = errorerror;rsqr2 = ymeyme;fe_rsqr2 = 1.0 - rsqr1/rsqr2
13、 % r-squared including fixed effectssige=results.sige(nobs-k)/nobs);loglikstfe=nobs/2log(2*pi*sige)-1/(2sige)*results.residresults.residlmsarsem_panel(results,w,ywith,xwith); % (robust) lm tests二、静态面板sar模型1、无固定效应(no fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)n+1;t2=t
14、n; wx(t1:t2,:)=w*x(t1:t2,:);endxconstant=ones(n*t,1);nobs k=size(x);info.lflag=0; info.model=0;info。fe=0; results=sar_panel_fe(y,xconstant x,w,t,info); vnames=strvcat(logcit,intercept,logp,logy);prt_spnew(results,vnames,1)% print out effects estimatesspat_model=0;direct_indirect_effects_estimates(re
15、sults,w,spat_model);panel_effects_sar(results,vnames,w);2、空间固定效应(spatial fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)*n+1;t2=tn; wx(t1:t2,:)=w*x(t1:t2,:);endxconstant=ones(nt,1);nobs k=size(x);info.lflag=0;info.model=1;info。fe=0; results=sar_panel_fe(y,x,w,t,info); vn
16、ames=strvcat(logcit,logp,logy);prt_spnew(results,vnames,1) print out effects estimatesspat_model=0;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sar(results,vnames,w);3、时点固定效应(time period fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t-1)*n+1;t2=t*n
17、; wx(t1:t2,:)=w*x(t1:t2,:);endxconstant=ones(nt,1);nobs k=size(x);info.lflag=0; required for exact resultsinfo.model=2;info.fe=0; do not print intercept and fixed effects; use info.fe=1 to turn onresults=sar_panel_fe(y,x,w,t,info); vnames=strvcat(logcit,logp,logy);prt_spnew(results,vnames,1) print o
18、ut effects estimatesspat_model=0;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sar(results,vnames,w);4、双固定效应(spatial and time period fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)n+1;t2=t*n; wx(t1:t2,:)=wx(t1:t2,:);endxconstant=ones(n*t,1);nobs k
19、=size(x);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_fe(y,x,w,t,info); vnames=strvcat(logcit,logp,logy);prt_spnew(results,vnames,1) print out effects estimatesspat_model=0;direct_indirect_effects_
20、estimates(results,w,spat_model);panel_effects_sar(results,vnames,w);三、静态面板sdm模型1、无固定效应(no fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)*n+1;t2=tn; wx(t1:t2,:)=wx(t1:t2,:);endxconstant=ones(nt,1);nobs k=size(x);info.lflag=0; info.model=0;info.fe=0; results=sar_panel_fe(
21、y,xconstant x wx,w,t,info); vnames=strvcat(logcit,intercept,logp,logy,w*logp,wlogy);prt_spnew(results,vnames,1)% print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sdm(results,vnames,w);2、空间固定效应(spatial fixed effects)t=30; n=46; w=normw(w1);
22、y=a(:,3);x=a(:,4,6); for t=1:t t1=(t-1)n+1;t2=tn; wx(t1:t2,:)=wx(t1:t2,:);endxconstant=ones(nt,1);nobs k=size(x);info。lflag=0; required for exact resultsinfo。model=1;info。fe=0; do not print intercept and fixed effects; use info。fe=1 to turn onresults=sar_panel_fe(y,x wx,w,t,info); vnames=strvcat(log
23、cit,logp,logy,wlogp,w*logy);prt_spnew(results,vnames,1) print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sdm(results,vnames,w);3、时点固定效应(time period fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)n+1;t2=tn; wx(t
24、1:t2,:)=w*x(t1:t2,:);endxconstant=ones(n*t,1);nobs k=size(x);info.lflag=0; % required for exact resultsinfo。model=2;info.fe=0; % do not print intercept and fixed effects; use info。fe=1 to turn on new routines to calculate effects estimatesresults=sar_panel_fe(y,x wx,w,t,info); vnames=strvcat(logcit,
25、logp,logy,w*logp,wlogy);% print out coefficient estimatesprt_spnew(results,vnames,1)% print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sdm(results,vnames,w)4、双固定效应(spatial and time period fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(
26、:,4,6); for t=1:t t1=(t-1)n+1;t2=tn; wx(t1:t2,:)=wx(t1:t2,:);endxconstant=ones(nt,1);nobs k=size(x);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_fe(y,x wx,w,t,info); vnames=strvcat(lo
27、gcit,logp,logy,wlogp,wlogy);prt_spnew(results,vnames,1) print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sdm(results,vnames,w)wald test spatial lag% wald test for spatial durbin model against spatial lag modelbtemp=results。parm;varcov=resu
28、lts。cov;rafg=zeros(k,2*k+2);for k=1:k rafg(k,k+k)=1; r(1,3)=0 and r(2,4)=0;endwald_spatial_lag=(rafgbtemp)inv(rafgvarcovrafg)rafg*btempprob_spatial_lag=1-chis_cdf (wald_spatial_lag, k)wald test spatial error% wald test spatial durbin model against spatial error modelr=zeros(k,1);for k=1:k r(k)=btemp
29、(2*k+1)*btemp(k)+btemp(k+k); % k changed in 1, 7/12/2010% r(1)=btemp(5)*btemp(1)+btemp(3);% r(2)=btemp(5)btemp(2)+btemp(4);endrafg=zeros(k,2*k+2);for k=1:k rafg(k,k) =btemp(2*k+1); % k changed in 1, 7/12/2010 rafg(k,k+k) =1; rafg(k,2k+1)=btemp(k); rafg(1,1)=btemp(5);rafg(1,3)=1;rafg(1,5)=btemp(1); r
30、afg(2,2)=btemp(5);rafg(2,4)=1;rafg(2,5)=btemp(2);end wald_spatial_error=rinv(rafgvarcovrafg)*rprob_spatial_error=1chis_cdf (wald_spatial_error,k)lr test spatial lagresultssar=sar_panel_fe(y,x,w,t,info); lr_spatial_lag=-2(resultssar。lik-results。lik)prob_spatial_lag=1chis_cdf (lr_spatial_lag,k) lr tes
31、t spatial errorresultssem=sem_panel_fe(y,x,w,t,info); lr_spatial_error=-2(resultssem。likresults。lik)prob_spatial_error=1chis_cdf (lr_spatial_error,k) 5、空间随机效应与时点固定效应模型t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)n+1;t2=t*n; wx(t1:t2,:)=wx(t1:t2,:);endxconstant=ones(nt,1);nobs k=size
32、(x);ywith,xwith,meanny,meannx,meanty,meantx=demean(y,x wx,n,t,2); % 2=time dummiesinfo。model=1;results=sar_panel_re(ywith,xwith,w,t,info); prt_spnew(results,vnames,1)spat_model=1;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sdm(results,vnames,w)wald test spatial lagbtemp=res
33、ults.parm(1:2k+2);varcov=results。cov(1:2k+2,1:2*k+2);rafg=zeros(k,2*k+2);for k=1:k rafg(k,k+k)=1; % r(1,3)=0 and r(2,4)=0;endwald_spatial_lag=(rafg*btemp)*inv(rafg*varcov*rafg)*rafg*btempprob_spatial_lag= 1-chis_cdf (wald_spatial_lag, k) wald test spatial errorr=zeros(k,1);for k=1:k r(k)=btemp(2k+1)
34、btemp(k)+btemp(k+k); % k changed in 1, 7/12/2010 r(1)=btemp(5)btemp(1)+btemp(3);% r(2)=btemp(5)btemp(2)+btemp(4);endrafg=zeros(k,2*k+2);for k=1:k rafg(k,k) =btemp(2*k+1); % k changed in 1, 7/12/2010 rafg(k,k+k) =1; rafg(k,2*k+1)=btemp(k); rafg(1,1)=btemp(5);rafg(1,3)=1;rafg(1,5)=btemp(1);% rafg(2,2)
35、=btemp(5);rafg(2,4)=1;rafg(2,5)=btemp(2);end wald_spatial_error=rinv(rafg*varcov*rafg)*rprob_spatial_error= 1-chis_cdf (wald_spatial_error,k) lr test spatial lagresultssar=sar_panel_re(ywith,xwith(:,1:k),w,t,info); lr_spatial_lag=-2*(resultssar。lik-results。lik)prob_spatial_lag=1-chis_cdf (lr_spatial
36、_lag,k) lr test spatial errorresultssem=sem_panel_re(ywith,xwith(:,1:k),w,t,info); lr_spatial_error=2*(resultssem.likresults。lik)prob_spatial_error=1chis_cdf (lr_spatial_error,k)四、静态面板sem模型1、无固定效应(no fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)*n+1;t2=t*n; wx(t1:t2,:)
37、=w*x(t1:t2,:);endxconstant=ones(n*t,1);nobs k=size(x);info.lflag=0; info.model=0;info.fe=0; results=sem_panel_fe(y,xconstant x,w,t,info); vnames=strvcat(logcit,intercept,logp,logy);prt_spnew(results,vnames,1)% print out effects estimatesspat_model=0;direct_indirect_effects_estimates(results,w,spat_m
38、odel);panel_effects_sar(results,vnames,w);2、空间固定效应(spatial fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)n+1;t2=t*n; wx(t1:t2,:)=wx(t1:t2,:);endxconstant=ones(n*t,1);nobs k=size(x);info.lflag=0;info。model=1;info。fe=0; results=sem_panel_fe(y,x,w,t,info); vnames=strvcat(l
39、ogcit,logp,logy);prt_spnew(results,vnames,1)% print out effects estimatesspat_model=0;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sar(results,vnames,w);3、时点固定效应(time period fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)n+1;t2=t*n; wx(t1:t2,:)=w
40、x(t1:t2,:);endxconstant=ones(n*t,1);nobs k=size(x);info.lflag=0; % required for exact resultsinfo。model=2;info.fe=0; do not print intercept and fixed effects; use info。fe=1 to turn onresults=sem_panel_fe(y,x,w,t,info); vnames=strvcat(logcit,logp,logy);prt_spnew(results,vnames,1)% print out effects e
41、stimatesspat_model=0;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sar(results,vnames,w);4、双固定效应(spatial and time period fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t-1)n+1;t2=tn; wx(t1:t2,:)=wx(t1:t2,:);endxconstant=ones(n*t,1);nobs k=size(x);inf
42、o。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_fe(y,x,w,t,info); vnames=strvcat(logcit,logp,logy);prt_spnew(results,vnames,1) print out effects estimatesspat_model=0;direct_indirect_effects_estimates(
43、results,w,spat_model);panel_effects_sar(results,vnames,w);五、静态面板sdem模型1、无固定效应(no fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t-1)*n+1;t2=t*n; wx(t1:t2,:)=w*x(t1:t2,:);endxconstant=ones(nt,1);nobs k=size(x);info。lflag=0; info。model=0;info.fe=0; results=sem_panel_fe(y,xcon
44、stant x wx,w,t,info); vnames=strvcat(logcit,intercept,logp,logy,wlogp,w*logy);prt_spnew(results,vnames,1) print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sdm(results,vnames,w);2、空间固定效应(spatial fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for t=1:t t1=(t1)*n+1;t2=t*n; wx(t1:t2,:)=w*x(t1:t2,:);endxconstant=ones(n*t,1);nobs k=size(x);info.lflag=0; required for exact resultsinfo。model=1;info.fe=0; do not print intercept and
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 感谢员工的演讲稿6篇
- 安全大反思的心得5篇
- 美术幼儿教师工作总结8篇
- 初中物理培训总结6篇
- 音乐生有关的工作计划6篇
- 湖南省长沙市宁乡市2023-2024学年四年级下学期6月期末道德与法治试题
- 幼儿园教案音乐律动的快乐时光
- 中国民生银行汕头分行2023年校园招聘人员笔试上岸历年典型考题与考点剖析附带答案详解
- 中国工商银行西藏自治区分行2023年校园招聘15名人员笔试上岸历年典型考题与考点剖析附带答案详解
- 中国工商银行数据中心2023年度春季招聘55名人员笔试上岸历年典型考题与考点剖析附带答案详解
- 电影赏析绿皮书课件(内容详细)
- 浙江省杭州市钱塘区2022-2023学年二年级下学期期末数学检测卷
- 2023年江苏省连云港市海州区数学五下期末达标检测试题含解析
- GB/T 7025.1-2023电梯主参数及轿厢、井道、机房的型式与尺寸第1部分:Ⅰ、Ⅱ、Ⅲ、Ⅵ类电梯
- 卫生院先诊疗、后付费自查报告
- 数学-九宫数独100题(附答案)
- 从化区村落品牌VI设计实践与探索
- 一种敏捷的实践教学模式探索
- 楷书四大家ppt件
- 新时期加强老干部工作中存在的问题及对策建议思考
- 择日实用大全袁先胜整理
评论
0/150
提交评论