实在不知道哪里错了,新手一枚,求大神解答~
T=9; % number of time periods
N=24; % number of regions
I=eye(T);
W=kron(I,YangtzeQueen);
% row-normalize W
% y=A(:,[1]); % column number in the data matrix that corresponds to the dependent variable
% x=A(:,[2,3); % column numbers in the data matrix that correspond to the independent variables
y=Yangtze24A(:,[1]);
x=Yangtze24A(:,[2:3]);
% for t=1:T
% t1=(t-1)*N+1;t2=t*N;
% wx(t1:t2,:)=W*x(t1:t2,:);
% end
xconstant=ones(N*T,1);
[nobs K]=size(x);
% ----------------------------------------------------------------------------------------
% ols estimation
results=ols(y,[xconstant x]);
vnames=strvcat('y','intercept','lnHotel','lnEC_U');
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
% ----------------------------------------------------------------------------------------
% 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('y','intercept','lnHotel','lnEC_U'); % 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
lm4=lmerror_robust_panel(ywith,xwith,W);
prt_tests(lm4);
% ----------------------------------------------------------------------------------------
% 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=strvcat('y','intercept','lnHotel','lnEC_U'); % 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);
error=y-kron(tfe,en)-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);
logliktfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests
lm4=lmerror_robust_panel(ywith,xwith,W);
prt_tests(lm4);
% ----------------------------------------------------------------------------------------
% 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('y','intercept','lnHotel','lnEC_U'); % should be changed if x is changed
prt_reg(results,vnames);
intercept=mean(y)-mean(x)*results.beta;
sfe=meanny-meannx*results.beta-kron(en,intercept);
tfe=meanty-meantx*results.beta-kron(et,intercept);
yme = y - mean(y);
ent=ones(N*T,1);
error=y-kron(tfe,en)-kron(et,sfe)-x*results.beta-kron(ent,intercept);
rsqr1 = error'*error;
rsqr2 = yme'*yme;0
FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effects
sige=results.sige*((nobs-K)/nobs);
loglikstfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
LM test no spatial lag, probability = 1.2515, 0.263
robust LM test no spatial lag, probability = 0.1061, 0.745
LM test no spatial error, probability = 1.5030, 0.220
robust LM test no spatial error, probability = 0.3577, 0.550
LM lag test for omitted spatial lag
LM value 1.25145592
Marginal Probability 0.26327459
chi(1) .01 value 6.64000000
??? Error using ==> prt_tests at 171
results structure not known by prt_spat function