sunhui116 发表于 2012-8-9 11:25 
一般我们用的比较简单的权重矩阵就是二元邻接权重,相邻为1,不相邻为0,你在31*31的权重矩阵上改一下就行 ...
嗯,我已经把它更改过来了~~但仍然非常谢谢楼主! 由于我的数据读取遇到问题,故再次向楼主请教一下,按jplv7中所给的格式:“A=wk1read('cigardemo.wk1',1,0);W1=wk1read('Spat-Sym-US.wk1');”应该怎么对之更改从而才能读取到自己的数据呢?我的总数据矩阵名为“MPC”,空间权重矩阵名为“W2”。我输入的命令为:
“clear all;
A=wk1read('MPC');
W2=wk1read('W1');
T=20; % number of time periods
N=30; % number of regions
% row-normalize W
W=normw(W2); % function of LeSage
y=A(:,[1]); % column number in the data matrix that corresponds to the dependent variable
x=A(:,[3,4,5,7,8,9,10,11,12,13]); % 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('per2','intercept','lK','lz','lrwork2','ltech','lperh','lrfdi','lopen','lurban','lgover','labor');
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('per2','intercept','lK','lz','lrwork2','ltech','lperh','lrfdi','lopen','lurban','lgover','labor'); % 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('per2','intercept','lK','lz','lrwork2','ltech','lperh','lrfdi','lopen','lurban','lgover','labor'); % should be changed if x is changed
prt_reg(results,vnames);
LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests”
但是其结果却显示出了MPC矩阵中的所有数据!烦劳指教,十分感谢啊!