文档详情

用MATLAB做空间计量回归详细步骤(有截图).docx

发布:2018-04-10约1.83万字共17页下载文档
文本预览下载声明
用MATLAB做空间计量回归详细步骤(有截图)1.将elhorst和jplv7两个程序文件夹复制到MATLAB安装目录的toolbox文件夹2.设置路径:3.读入变量和权重数据A=xlsread(D:\desktop\elhorst_model\\cigarette.xls);%读入数据,你自己的数据,数据格式自己定义。W1=xlsread(D:\desktop\elhorst_model\Spat-Sym-US.xls); %读入你的权重文件。4.根据所用模型,选择附录中的对应的运行程序,得出结果%例如,以下是普通面板编程T=30; %该面板数据的时期数为30(T=30),N=46; %该面板数据有30个地区(N=30),W=normw(W1); %将空间权重矩阵标准化(W=normw(w1)),y=A(:,3); %将名为A(以矩阵形式出现在MATLABA中)的变量的第3列数据定义为被解释变量y,x=A(:,[4,6]); %将名为A的变量的第4、5、6列数据定义为解释变量矩阵x,xconstant=ones(N*T,1); %定义一个有N*T行,1列的全1矩阵,该矩阵名为:xconstant,(ones即为全1矩阵)[nobs K]=size(x); %说明解释变量矩阵x的大小:有nobs行,K列。(size为描述矩阵的大小)。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(2*pi*sige)-1/(2*sige)*results.resid*results.resid% The (robust)LM tests developed by ElhorstLMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests附录:静态面板空间计量经济学一、OLS静态面板编程1、普通面板编程T=30; N=46; W=normw(W1); y=A(:,3); x=A(:,[4,6]); xconstant=ones(N*T,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(2*pi*sige)-1/(2*sige)*results.resid*results.resid% The (robust)LM tests developed by ElhorstLMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests2、空间固定OLS (spatial-fixed 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]=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-meannx*results.beta; % including the constant termyme = y - mean(y);et=ones(T,1);error=y-kron(et,sfe)-x*results.beta;rsqr1 = error*error;rsqr2 = yme*yme;FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effectssige=results.sige*((nobs-K)/nobs);logliksfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid*results.residLMsarsem_panel(results,W,ywith,xwith); % (R
显示全部
相似文档