悬赏 15 个论坛币 已解决
实在不知道哪里错了,新手一枚,求大神解答~
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
% The (robust)LM tests developed by Elhorst
LMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests
% The lm tests developed by Donald Lacombe
% see http://www.rri.wvu.edu/lacombe/~lacombe.htm
lm1=lmlag(y,[xconstant x],W);
prt_tests(lm1);
lm2=lmerror_panel(y,[xconstant x],W);
prt_tests(lm2);
lm3=lmlag_robust_panel(y,[xconstant x],W);
prt_tests(lm3);
lm4=lmerror_robust_panel(y,[xconstant x],W);
prt_tests(lm4);
% ----------------------------------------------------------------------------------------
% 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
lm1=lmlag_panel(ywith,xwith,W);
prt_tests(lm1);
lm2=lmerror_panel(ywith,xwith,W);
prt_tests(lm2);
lm3=lmlag_robust_panel(ywith,xwith,W);
prt_tests(lm3);
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
lm1=lmlag_panel(ywith,xwith,W);
prt_tests(lm1);
lm2=lmerror_panel(ywith,xwith,W);
prt_tests(lm2);
lm3=lmlag_robust_panel(ywith,xwith,W);
prt_tests(lm3);
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
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests
lm1=lmlag_panel(ywith,xwith,W);
prt_tests(lm1);
lm2=lmerror_panel(ywith,xwith,W);
prt_tests(lm2);
lm3=lmlag_robust_panel(ywith,xwith,W);
prt_tests(lm3);
lm4=lmerror_robust_panel(ywith,xwith,W);
prt_tests(lm4);
% ----------------------------------------------------------------------------------------
% Tests for the joint significance of spatial and/or time-period fixed effects
LR=-2*(logliktfe-loglikstfe);
dof=N;
probability=1-chis_prb(LR,dof);
% Note: probability > 0.05 implies rejection of spatial fixed effects
fprintf(1,'LR-test joint significance spatial fixed effects, degrees of freedom and probability = %9.4f,%6d,%9.4f \n',LR,dof,probability);
LR=-2*(logliksfe-loglikstfe);
dof=T;
probability=1-chis_prb(LR,dof);
% Note: probability > 0.05 implies rejection of spatial fixed effects
fprintf(1,'LR-test joint significance time-periode fixed effects, degrees of freedom and probability = %9.4f,%6d,%9.4f \n',LR,dof,probability);
Ordinary Least-squares Estimates
Dependent Variable = y
R-squared = 0.1098
Rbar-squared = 0.1014
sigma^2 = 0.0001
Durbin-Watson = 1.5768
Nobs, Nvars = 216, 3
***************************************************************
Variable Coefficient t-statistic t-probability
intercept 1.079998 35.788997 0.000000
lnHotel -0.000784 -2.652166 0.008600
lnEC_U -0.000636 -1.992909 0.047548
loglikols =
750.3025
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