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
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
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
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
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?
楼主你好,问下一,以上四个模型中的哪个MORAN I 值来判断存在空间自相关性?每个模型结果后面的这些是什么意思?
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