资源简介
本代码可以计算出空间计量经济学模型的参数,并做出检验!
代码片段和文件信息
A=wk1read(‘C:\Program Files\MATLAB\R2010a\elhorst\cigarette.wk1‘10); % data set with T=30
W1=wk1read(‘C:\Program Files\MATLAB\R2010a\elhorst\Spat-Sym-US.wk1‘);
% Dataset downloaded from www.wiley.co.uk/baltagi/
% Spatial weights matrix constructed by Elhorst
%
% written by: J.Paul Elhorst summer 2010
% University of Groningen
% Department of Economics
% 9700AV Groningen
% the Netherlands
% j.p.elhorst@rug.nl
%
% REFERENCES:
% Elhorst JP (2010) Matlab Software for Spatial Panels. Under review.
%
% Elhorst JP (2010) Spatial Panel Data Models. In Fischer MM Getis A (Eds.)
% Handbook of Applied Spatial Analysis Ch. C.2. Springer: Berlin Heidelberg New York.
%
% dimensions of the problem
T=30; % number of time periods
N=46; % number of regions
% row-normalize W
W=normw(W1); % function of LeSage
y=A(:[3]); % column number in the data matrix that corresponds to the dependent variable
x=A(:[46]); % column numbers in the data matrix that correspond to the independent variables
xconstant=ones(N*T1);
[nobs K]=size(x);
% ----------------------------------------------------------------------------------------
% ols estimation
results=ols(y[xconstant x]);
vnames=strvcat(‘logcit‘‘intercept‘‘logp‘‘logy‘);
prt_reg(resultsvnames1);
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(resultsWy[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;
[ywithxwithmeannymeannxmeantymeantx]=demean(yxNTmodel);
results=ols(ywithxwith);
vnames=strvcat(‘logcit‘‘logp‘‘logy‘); % should be changed if x is changed
prt_reg(resultsvnames);
sfe=meanny-meannx*results.beta; % including the constant term
yme = y - mean(y);
et=ones(T1);
error=y-kron(etsfe)-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(resultsWywithxwith); % (Robust) LM tests
lm1=lmlag_panel(ywithxwithW);
prt_tests(lm1);
lm2=lmerror_panel(ywithxwithW);
prt_tests(lm2);
lm3=lmlag_robust_panel(ywithxwithW);
prt_tests(lm3);
lm4=lmerror_robust_panel(ywithxwithW);
prt_tests(lm4);
% -------------------------------------------------------------
评论
共有 条评论