六步学会用MATLAB做空间计量回归详细步骤
- 格式:doc
- 大小:548.50 KB
- 文档页数:33
1.excel与MATLAB:
Excel:
选项——加载项——COM加载项——转到——没有勾选项
2. MATLAB安装目录中寻找toolbox——exlink——点击,启用宏
E:\MATLAB\toolbox\exlink
然后,Excel中就出现MATLAB工具
(注意Excel中的数据:)
3.启动matlab
(1)点击start MATLAB
(2)senddata to matlab ,并对变量矩阵变量进行命名(注意:选取变量为数值,不包括各变量)
(data表中数据进行命名)
(空间权重进行命名)
(3)导入MATLAB中的两个矩阵变量就可以看见
4.将elhorst和jplv7两个程序文件夹复制到MATLAB安装目录的toolbox文件夹
5.设置路径:
6.输入程序,得出结果
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 Elhorst
LMsarsem_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 Elhorst
LMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests
2、空间固定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,mo del);
results=ols(ywith,xwith);
vnames=strvcat('logcit','logp','logy'); % should be changed if x is changed
prt_reg(results,vnames);
sfe=meanny-meannx*results.beta; % including the constant term yme = 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 effects
sige=results.sige*((nobs-K)/nobs);
logliksfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'* results.resid
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests 3、时期固定OLS(time-period 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=2;
[ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,mo del);
results=ols(ywith,xwith);
vnames=strvcat('logcit','logp','logy'); % should be changed if x is changed
prt_reg(results,vnames);
tfe=meanty-meantx*results.beta; % including the constant term yme = y - mean(y);
en=ones(N,1);