用matlab12b做空间回归,在设定vnames总出问题,最后常数项的结果回归不出来。不知道怎么回事。
普通的OLS结果能够做出来,但是加入固定效应以后,vnames设定就无效了,程序语言如下(按照jplv7里的demo写的):
普通ols:
% ols estimation
results=ols(y,[xconstant x]);
vnames=strvcat('y','intercept','x1','x2','x3','x4');
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
%
加了空间固定效应的ols:
% 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','x1','x2','x3','x4'); % 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
%
这个结果就不好了,没有常数项系数
Wrong # of variable names in prt_reg -- check vnames argument
will use generic variable names
Ordinary Least-squares Estimates
R-squared = 0.8304
Rbar-squared = 0.8291
sigma^2 = 0.0196
Durbin-Watson = 0.2092
Nobs, Nvars = 403, 4
***************************************************************
Variable Coefficient t-statistic t-probability
variable 1 1.050876 5.581297 0.000000
variable 2 -1.145020 -3.846318 0.000140
variable 3 -0.486029 -3.052245 0.002423
variable 4 0.005534 2.035847 0.042426
尝试了几次,用了别的语言还是不行,请帮忙找找什么原因?