本人最近正在学习空间面板,经过几天努力,有点收获,也有点困惑,在此与大家分享(使用的是空间计量程序包jplv7,下载及详细说明参见https://bbs.pinggu.org/thread-1296997-1-1.html)。使用Moran'I 和LM进行空间自相关检验,程序如下:
clear all;
%sp.mat 中数据已取对数
format long
format compact
load sp.mat;
% dimensions of the problem
T=13; % number of time periods
N=29; % number of regions
% row-normalize W
W=normw(w1); % function of LeSage
y=sp(:,[1]); % column number in the data matrix that corresponds to the dependent variable
x=sp(:,[2:8]); % column numbers in the data matrix that correspond to the independent variables
xconstant=ones(N*T,1);
[nobs K]=size(x);
% ----------------------------------------------------------------------------------------
% ols estimation (一般面板模型)
results=ols(y,[xconstant x]);
vnames=char('EF','C','UR','TR','DA','PCG','RD','OD','GOV');
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
LMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests
%moran 检验
I=eye(T);W1=kron(I,W);
res=moran(y,[xconstant x],W1);
prt(res);
% ----------------------------------------------------------------------------------------
% spatial fixed effects + (robust) LM tests for spatial lag and spatial error model(空间固定效应模型)
% fixed effects, within estimator
% demeaning of the y and x variables
model=1;
[ywith,xwith,meanny,meannx,~,meantx]=demean(y,x,N,T,model);
results=ols(ywith,xwith);
vnames=char('EF','UR','TR','DA','PCG','RD','OD','GOV'); % should be changed if x is changed
prt_reg(results,vnames);
FE=meanny-meannx*results.beta; % including the constant term
yme = y - mean(y);
ee=ones(T,1);
error=y-kron(ee,FE)-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);
loglikfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests
%moran检验
res=moran(ywith,xwith,W1);
prt(res);
% ----------------------------------------------------------------------------------------
% time period fixed effects + (robust) LM tests for spatial lag and spatial error model(时间固定效应模型)
% fixed effects, within estimator
% demeaning of the y and x variables
model=2;
[ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);
results=ols(ywith,xwith);
vnames=char('EF','UR','TR','DA','PCG','RD','OD','GOV'); % should be changed if x is changed
prt_reg(results,vnames);
sige=results.sige*((nobs-K)/nobs);
loglikfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests
%moran检验
res=moran(ywith,xwith,W1);
prt(res);
% ----------------------------------------------------------------------------------------
% spatial and time period fixed effects + (robust) LM tests for spatial lag and spatial error model(时空固定效应模型)
% fixed effects, within estimator
% demeaning of the y and x variables
model=3;
[ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);
results=ols(ywith,xwith);
vnames=char('EF','UR','TR','DA','PCG','RD','OD','GOV'); % should be changed if x is changed
prt_reg(results,vnames);
sige=results.sige*((nobs-K)/nobs);
loglikfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests
%moran检验
res=moran(ywith,xwith,W1);
prt(res);
运行结果如下:
一般面板模型
Ordinary Least-squares Estimates
Dependent Variable = EF
R-squared = 0.4144
Rbar-squared = 0.4033
sigma^2 = 0.2539
Durbin-Watson = 1.3333
Nobs, Nvars = 377, 8
***************************************************************
Variable Coefficient t-statistic t-probability
C -7.222133 -6.480526 0.000000
UR 0.457273 2.138987 0.033093
TR -1.120515 -4.889903 0.000002
DA 0.074376 1.416657 0.157427
PCG 0.181680 1.788213 0.074562
RD -0.210588 -3.486601 0.000548
OD -0.168533 -3.904503 0.000112
GOV 2.375192 7.312403 0.000000
loglikols =
-2.725336719885613e+02
LM test no spatial lag, probability = 284.6915, 0.0000
robust LM test no spatial lag, probability = 64.1514, 0.0000
LM test no spatial error, probability = 221.0690, 0.0000
robust LM test no spatial error, probability = 0.5289, 0.4671
Moran I-test for spatial correlation in residuals
Moran I 0.53544331
Moran I-statistic 15.22260869
Marginal Probability 0.00000000
mean -0.00748302
standard deviation 0.03566579
空间固定效应模型
Ordinary Least-squares Estimates
Dependent Variable = EF
R-squared = 0.8557
Rbar-squared = 0.8534
sigma^2 = 0.0097
Durbin-Watson = 1.2812
Nobs, Nvars = 377, 7
***************************************************************
Variable Coefficient t-statistic t-probability
UR 0.391384 4.639076 0.000005
TR -0.151636 -1.910552 0.056835
DA -0.143382 -4.447815 0.000011
PCG 0.489207 13.864206 0.000000
RD 0.036898 1.089596 0.276600
OD -0.028787 -1.305522 0.192527
GOV 0.000780 0.006636 0.994709
FE_rsqr2 =
0.977679091049534
loglikfe =
3.433207036098033e+02
LM test no spatial lag, probability = 88.9056, 0.0000
robust LM test no spatial lag, probability = 6.1404, 0.0132
LM test no spatial error, probability = 89.2450, 0.0000
robust LM test no spatial error, probability = 6.4799, 0.0109
Moran I-test for spatial correlation in residuals
Moran I 0.34020575
Moran I-statistic 9.68198649
Marginal Probability 0.00000000
mean -0.00476057
standard deviation 0.03562971
时间固定效应模型
Ordinary Least-squares Estimates
Dependent Variable = EF
R-squared = 0.3790
Rbar-squared = 0.3690
sigma^2 = 0.2334
Durbin-Watson = 1.6949
Nobs, Nvars = 377, 7
***************************************************************
Variable Coefficient t-statistic t-probability
UR -0.098575 -0.421150 0.673890
TR -1.265596 -5.621611 0.000000
DA 0.068341 1.351996 0.177202
PCG 0.681905 4.886032 0.000002
RD -0.158074 -2.675861 0.007785
OD -0.313482 -6.258943 0.000000
GOV 3.080287 8.901788 0.000000
loglikfe =
-2.571671427739816e+02
LM test no spatial lag, probability = 239.1127, 0.0000
robust LM test no spatial lag, probability = 160.5577, 0.0000
LM test no spatial error, probability = 104.4534, 0.0000
robust LM test no spatial error, probability = 25.8984, 0.0000
Moran I-test for spatial correlation in residuals
Moran I 0.36805337
Moran I-statistic 10.32135589
Marginal Probability 0.00000000
mean -0.00271308
standard deviation 0.03592226
时空固定效应模型
Ordinary Least-squares Estimates
Dependent Variable = EF
R-squared = 0.3354
Rbar-squared = 0.3246
sigma^2 = 0.0069
Durbin-Watson = 1.7296
Nobs, Nvars = 377, 7
***************************************************************
Variable Coefficient t-statistic t-probability
UR 0.274998 3.725420 0.000225
TR -0.246133 -3.290118 0.001098
DA -0.143872 -5.193851 0.000000
PCG 0.429168 5.984491 0.000000
RD 0.091584 3.010201 0.002790
OD -0.170716 -7.142274 0.000000
GOV 0.178417 1.681508 0.093508
loglikfe =
4.068840511380279e+02
LM test no spatial lag, probability = 28.4240, 0.0000
robust LM test no spatial lag, probability = 31.6752, 0.0000
LM test no spatial error, probability = 9.7720, 0.0018
robust LM test no spatial error, probability = 13.0233, 0.0003
Moran I-test for spatial correlation in residuals
Moran I 0.11257500
Moran I-statistic 3.12990565
Marginal Probability 0.00174862
mean -0.00004290
standard deviation 0.03598125
本人认为结果说明存在显著的空间自相关性,同时,由于空间固定效应模型拟合优度较高,计量模型应该选用空间固定效应。但是本人的疑惑是由于LMLAG和LMER的检验结果相似,如何选择SAR、SEM、SDM?