全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 MATLAB等数学软件专版
17147 27
2013-01-29
我在用matlab做空间面板时,遇到几个问题,具体的操作如下:
权重矩阵(W1)和变量矩阵(A)在附件里
LM检验的命令为:
T=9; % number of time periods
N=55; % number of regions
% row-normalize W
W=normw(W1); % function of LeSage
y=A(:,[1]); % column number in the data matrix that corresponds to the dependent variable
x=A(:,[2:11]); % column numbers in the data matrix that correspond to the independent variables
xconstant=ones(N*T,1);
[nobs K]=size(x);
% ---------------------------------------------------------------------------------------
% ols estimation
results=ols(y,[xconstant x]);
vnames=strvcat('crste','PGDP','MIDU','EDU','PIN','PEX','PJIJIAN','CHENGZHEN','SZGX','TREAT','EFFECT');
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
% ----------------------------------------------------------------------------------------
% 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('crste','PGDP','MIDU','EDU','PIN','PEX','PJIJIAN','CHENGZHEN','SZGX','TREAT','EFFECT'); % 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
% ----------------------------------------------------------------------------------------
% 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('crste','PGDP','MIDU','EDU','PIN','PEX','PJIJIAN','CHENGZHEN','SZGX','TREAT','EFFECT'); % should be changed if x is changed
prt_reg(results,vnames);
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.5555
Rbar-squared   =    0.5463
sigma^2        =    0.0200
Durbin-Watson  =    1.7191
Nobs, Nvars    =    495,    11
***************************************************************
Variable         Coefficient      t-statistic    t-probability
variable 1          0.671015         4.589867         0.000006
variable 2          0.074995         2.970968         0.003116
variable 3          0.109128         7.962159         0.000000
variable 4          0.673918         1.384733         0.166772
variable 5         -0.092080        -4.879901         0.000001
variable 6         -0.204196       -10.168544         0.000000
variable 7          0.013275         1.112598         0.266433
variable 8          0.076925         0.949029         0.343079
variable 9          0.038177         1.291779         0.197050
variable 10         0.155732         3.955480         0.000088
variable 11        -0.010064        -0.271933         0.785789

loglikols =
  270.9526
Warning: Matrix is singular to working precision.
Warning: Matrix is singular to working precision.
Warning: Matrix is singular to working precision.
Warning: Matrix is singular to working precision.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  4.047746e-35.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  6.423347e-36.
Warning: Matrix is singular to working precision.
Warning: Matrix is singular to working precision.
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate.
RCOND =  9.370064e-36.
LM test no spatial lag, probability          =       NaN,      NaN
robust LM test no spatial lag, probability   =       NaN,      NaN
LM test no spatial error, probability        =   80.5333,   0.0000
robust LM test no spatial error, probability =       NaN,      NaN
Warning: Matrix is singular to working precision.
Ordinary Least-squares Estimates
Dependent Variable =        crste     
R-squared      =       NaN
Rbar-squared   =       NaN
sigma^2        =       NaN
Durbin-Watson  =       NaN
Nobs, Nvars    =    495,    10
***************************************************************
Error using betainc
X must be in the interval [0,1].
Error in tdis_prb (line 35)
tmp = 1.0 - 0.5*betainc(x2,0.5*n,0.5);
Error in prt_reg (line 364)
tout = tdis_prb(results.tstat,nobs-nvar); % find t-stat probabilities
Error in SHS_LMtest (line 26)
prt_reg(results,vnames);
本人是初学,还请哪位大虾指点一下,不胜感激!
二维码

扫码加我 拉你入群

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

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

全部回复
2013-1-29 19:31:01
佩服做空间计量的人。
二维码

扫码加我 拉你入群

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

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

2013-1-29 19:41:16
正学习中
二维码

扫码加我 拉你入群

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

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

2013-1-29 22:41:22
初学,不过注意到在ols第二行,你设了”xconstant“,也就是常数项,但是在vname里,缺少了对常数项的命名,这样就造成了变量数量和名称数量个数不等。我想大概是因为这个~
二维码

扫码加我 拉你入群

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

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

2013-1-29 22:43:32
remlus 发表于 2013-1-29 19:31
佩服做空间计量的人。
没办法的办法,呵呵
二维码

扫码加我 拉你入群

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

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

2013-1-29 22:50:55
胖胖和瘦瘦 发表于 2013-1-29 22:41
初学,不过注意到在ols第二行,你设了”xconstant“,也就是常数项,但是在vname里,缺少了对常数项的命名, ...
谢谢!我尝试一下!还有一个问题就是权重矩阵的行列式为0,这个是不是也会影响,若是的话,您知道怎么修正吗,先谢谢您了!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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