权重矩阵(W1)和变量矩阵(A)在附件里
LM检验的命令为:
T=9; % number of time periods
N=55; % number of regions
% row-normalize W
W=normw(W1); % function of LeSage
y=A(:,[1]); % column number in the data matrix that corresponds to the dependent variable
x=A(:,[2:11]); % 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=strvcat('crste','PGDP','MIDU','EDU','PIN','PEX','PJIJIAN','CHENGZHEN','SZGX','TREAT','EFFECT');
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
% ----------------------------------------------------------------------------------------
% 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,meanty,meantx]=demean(y,x,N,T,model);
results=ols(ywith,xwith);
vnames=strvcat('crste','PGDP','MIDU','EDU','PIN','PEX','PJIJIAN','CHENGZHEN','SZGX','TREAT','EFFECT'); % 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
% ----------------------------------------------------------------------------------------
% 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=strvcat('crste','PGDP','MIDU','EDU','PIN','PEX','PJIJIAN','CHENGZHEN','SZGX','TREAT','EFFECT'); % should be changed if x is changed
prt_reg(results,vnames);
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests
结果为:
Wrong # of variable names in prt_reg -- check vnames argument
will use generic variable names
Ordinary Least-squares Estimates
R-squared = 0.5555
Rbar-squared = 0.5463
sigma^2 = 0.0200
Durbin-Watson = 1.7191
Nobs, Nvars = 495, 11
***************************************************************
Variable Coefficient t-statistic t-probability
variable 1 0.671015 4.589867 0.000006
variable 2 0.074995 2.970968 0.003116
variable 3 0.109128 7.962159 0.000000
variable 4 0.673918 1.384733 0.166772
variable 5 -0.092080 -4.879901 0.000001
variable 6 -0.204196 -10.168544 0.000000
variable 7 0.013275 1.112598 0.266433
variable 8 0.076925 0.949029 0.343079
variable 9 0.038177 1.291779 0.197050
variable 10 0.155732 3.955480 0.000088
variable 11 -0.010064 -0.271933 0.785789
loglikols =
270.9526
Warning: Matrix is singular to working precision.
Warning: Matrix is singular to working precision.
Warning: Matrix is singular to working precision.
Warning: Matrix is singular to working precision.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND = 4.047746e-35.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND = 6.423347e-36.
Warning: Matrix is singular to working precision.
Warning: Matrix is singular to working precision.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND = 9.370064e-36.
LM test no spatial lag, probability = NaN, NaN
robust LM test no spatial lag, probability = NaN, NaN
LM test no spatial error, probability = 80.5333, 0.0000
robust LM test no spatial error, probability = NaN, NaN
Warning: Matrix is singular to working precision.
Ordinary Least-squares Estimates
Dependent Variable = crste
R-squared = NaN
Rbar-squared = NaN
sigma^2 = NaN
Durbin-Watson = NaN
Nobs, Nvars = 495, 10
***************************************************************
Error using betainc
X must be in the interval [0,1].
Error in tdis_prb (line 35)
tmp = 1.0 - 0.5*betainc(x2,0.5*n,0.5);
Error in prt_reg (line 364)
tout = tdis_prb(results.tstat,nobs-nvar); % find t-stat probabilities
Error in SHS_LMtest (line 26)
prt_reg(results,vnames);
本人是初学,还请哪位大虾指点一下,不胜感激!