全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
2686 7
2017-12-14
用matlab12b做空间回归,在设定vnames总出问题,最后常数项的结果回归不出来。不知道怎么回事。
普通的OLS结果能够做出来,但是加入固定效应以后,vnames设定就无效了,程序语言如下(按照jplv7里的demo写的):
普通ols:

% ols estimation

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

vnames=strvcat('y','intercept','x1','x2','x3','x4');

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

LMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests

%

加了空间固定效应的ols:

% 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','x1','x2','x3','x4'); % should be changed if x is changed

prt_reg(results,vnames);

FE=meanny-meannx*results.beta; % including the constant term

yme = y - mean(y);

ee=ones(T,1);

error=y-kron(ee,FE)-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);

loglikfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid

LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests

%

这个结果就不好了,没有常数项系数

Wrong # of variable names in prt_reg -- check vnames argument
will use generic variable names

Ordinary Least-squares Estimates
R-squared      =    0.8304
Rbar-squared   =    0.8291
sigma^2        =    0.0196
Durbin-Watson  =    0.2092
Nobs, Nvars    =    403,     4
***************************************************************
Variable        Coefficient      t-statistic    t-probability
variable 1         1.050876         5.581297         0.000000
variable 2        -1.145020        -3.846318         0.000140
variable 3        -0.486029        -3.052245         0.002423
variable 4         0.005534         2.035847         0.042426


尝试了几次,用了别的语言还是不行,请帮忙找找什么原因?
二维码

扫码加我 拉你入群

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

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

全部回复
2017-12-14 16:30:13
ddddddddddddddddd
二维码

扫码加我 拉你入群

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

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

2017-12-15 12:09:46
你这句写错了vnames=strvcat('y','intercept','x1','x2','x3','x4');
因为OLS的FE与OLS的non fixed effects在变量命名上格式不同,后者没有常数项,你需要把'intercept'这项删除,
你改写为vnames=strvcat('y','x1','x2','x3','x4');即可
二维码

扫码加我 拉你入群

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

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

2017-12-15 15:49:32
moon44 发表于 2017-12-15 12:09
你这句写错了vnames=strvcat('y','intercept','x1','x2','x3','x4');
因为OLS的FE与OLS的non fixed effect ...
太谢谢啦~还有一个问题和你请教下,就是很多paper里面ols的固定效应回归结果也列举出了constant,想问下运行出来的结果哪个是constant的估计值呢?

Ordinary Least-squares Estimates
Dependent Variable =      y  
R-squared      =    0.9871
Rbar-squared   =    0.9870
sigma^2        =    0.0019
Durbin-Watson  =    1.6794
Nobs, Nvars    =    403,     5
***************************************************************
Variable        Coefficient      t-statistic          t-probability
x1              1.283168        21.639621         0.000000
x2              0.010091         1.445234         0.149179
x3             -0.781380        -8.059859         0.000000
x4             -0.438328        -8.270101         0.000000



FE_rsqr2 =

    0.4573


logliktfe =

  689.0712

LM test no spatial lag, probability          =   12.1396,    0.000
robust LM test no spatial lag, probability   =    2.6269,    0.105
LM test no spatial error, probability        =   48.2206,    0.000
robust LM test no spatial error, probability =   38.7079,    0.000
二维码

扫码加我 拉你入群

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

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

2017-12-15 15:51:59
你上面这个结果里没有constant
constant就是intercept
二维码

扫码加我 拉你入群

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

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

2017-12-15 15:54:46
moon44 发表于 2017-12-15 15:51
你上面这个结果里没有constant
constant就是intercept
那我能否根据ols固定效应结果,自己算出截距项的估计值呢?
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
栏目导航
热门文章
推荐文章

说点什么

分享

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