matlab sfe编码,求助:请各位大牛看看,我用matlab做回归为什么会出现以下错误?...

题主及各位同仁,我今天碰到同样的问题,一样的提示错。我已经觉得,特来共享。

1.这是软件问题,不是数据问题。

2.具体出问题原因不清楚,但知道和格式有关系,似乎和回车有关系。

解决办法:

回到demo文件,从新复制出来到txt文本里面修改,然后再帖进去,不要用word。

下面是我成功解决的代码:

T=11;

N=67;

W=normw(W);

y=inc(:,1);

x=inc(:,[2:7]);

xconstant=ones(N*T,1);

[nobs K]=size(x);

%最小二乘法

results=ols(y,[xconstant x]);

vnames=char('y','intercept','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;

%空间依赖性的LM检验

LMsarsem_panel(results,W,y,[xconstant x]);

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);

%空间固定效应的LM检验

model=1;

[ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);

results=ols(ywith,xwith);

vnames=strvcat('y', 'x1','x2','x3','x4','x5','x6','x7');

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

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);

%----------------------------------------------------------------

%时间固定的LM检验

model=2;

[ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);

results=ols(ywith,xwith);

vnames=strvcat('y', 'x1','x2','x3','x4','x5','x6','x7'); % 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);

%时空双固定的LM检验

model=3;

[ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);

results=ols(ywith,xwith);

vnames=strvcat('y', 'x1','x2','x3','x4','x5','x6','x7'); % 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;

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);

% -----------------------------------------

%固定效应的LR显著性检验

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值