黑白电视机 发表于 2014-4-16 12:21
试试将“vnames=strvcat('cons','x1','x2','x3','x4'); ”改成“vnames=strvcat(‘y’,'cons','x1','x2','x ...
T=11; % number of time periods
N=31; % number of regions
% row-normalize W
W=normw(W1); % function of LeSage
y=A(:,[4]); % column number in the data matrix that corresponds to the dependent variable
x=A(:,[5,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=char('CXST','x1','x2','x3','x4','x5','x6','x7');
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_panel(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);
结果:
Wrong # of variable names in prt_reg -- check vnames argument
will use generic variable names
Ordinary Least-squares Estimates
R-squared = 0.0440
Rbar-squared = 0.0383
sigma^2 = 119.5661
Durbin-Watson = 0.3193
Nobs, Nvars = 341, 3
***************************************************************
Variable Coefficient t-statistic t-probability
variable 1 9.906080 11.754521 0.000000
variable 2 0.175004 1.236923 0.216974
variable 3 0.045317 3.524113 0.000483
loglikols =
-1.2980e+03
LM test no spatial lag, probability = 143.5858, 0.000
robust LM test no spatial lag, probability = 0.7348, 0.391
LM test no spatial error, probability = 144.8356, 0.000
robust LM test no spatial error, probability = 1.9846, 0.159
LM lag test for omitted spatial lag in panel data
LM value 143.58581315
Marginal Probability 0.00000000
chi(1) .01 value 6.64000000
LM error test for spatial errors in panel data
LM value 144.83556667
Marginal Probability 0.00000000
chi(1) .01 value 6.64000000
Robust LM lag test for omitted spatial lag in panel data
LM value 0.73480738
Marginal Probability 0.39132935
chi(1) .01 value 6.64000000
Robust LM error test for spatial errors in panel data
LM value 1.98456090
Marginal Probability 0.15891075
chi(1) .01 value 6.64000000