楼主: 樱空ぁ恋
2438 3

[问答] 求助!空间计量运行中出现错误 [推广有奖]

  • 7关注
  • 1粉丝

已卖:112份资源

博士生

30%

还不是VIP/贵宾

-

威望
0
论坛币
360 个
通用积分
0
学术水平
1 点
热心指数
2 点
信用等级
0 点
经验
18201 点
帖子
137
精华
0
在线时间
361 小时
注册时间
2012-1-29
最后登录
2018-6-20

楼主
樱空ぁ恋 发表于 2015-10-17 08:22:24 |AI写论文
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文件夹内就可以了啊!
关键词:空间计量 fixed effect significance Probability spatial lag 空间

本帖被以下文库推荐

沙发
yucuiting 发表于 2015-10-17 08:22:25
你的matlab软件中没有安装prt_spat函数,你在网上可以直接搜索,然后咱在你的bin文件夹内就可以了啊!
已有 2 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
胖胖小龟宝 + 10 + 10 热心帮助其他会员
樱空ぁ恋 + 2 + 1 + 1 + 1 精彩帖子

总评分: 经验 + 10  论坛币 + 12  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

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

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

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-5 20:50