全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 EViews专版
2394 3
2015-10-17
悬赏 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

最佳答案

yucuiting 查看完整内容

你的matlab软件中没有安装prt_spat函数,你在网上可以直接搜索,然后咱在你的bin文件夹内就可以了啊!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-10-17 08:22:25
你的matlab软件中没有安装prt_spat函数,你在网上可以直接搜索,然后咱在你的bin文件夹内就可以了啊!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-10-18 16:31:06
yucuiting 发表于 2015-10-17 15:50
你的matlab软件中没有安装prt_spat函数,你在网上可以直接搜索,然后咱在你的bin文件夹内就可以了啊!
好的,是必须要放在bin文件夹中吗?我所有文件都放一起的
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2019-3-13 09:06:10
请问有没有出现这个问题呀
Error in lmlag (line 47)        lm1 = (e'*W*y)/epe;
有人知道怎么解决吗
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群