楼主: weiqun890
16194 27

[问答] matlab做空间面板出现问题——NAN,怎么解决 [推广有奖]

  • 3关注
  • 2粉丝

高中生

60%

还不是VIP/贵宾

-

威望
0
论坛币
429 个
通用积分
1.0000
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
365 点
帖子
20
精华
0
在线时间
34 小时
注册时间
2010-7-3
最后登录
2020-12-29

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
我在用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);
本人是初学,还请哪位大虾指点一下,不胜感激! 权重矩阵和变量矩阵.txt (52.15 KB)
二维码

扫码加我 拉你入群

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

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

关键词:MATLAB atlab matla 空间面板 Mat 空间 面板 matlab

沙发
remlus 发表于 2013-1-29 19:31:01 |只看作者 |坛友微信交流群
佩服做空间计量的人。

使用道具

藤椅
周周啊 发表于 2013-1-29 19:41:16 |只看作者 |坛友微信交流群
正学习中
God Bless Me!

使用道具

板凳
胖胖和瘦瘦 发表于 2013-1-29 22:41:22 |只看作者 |坛友微信交流群
初学,不过注意到在ols第二行,你设了”xconstant“,也就是常数项,但是在vname里,缺少了对常数项的命名,这样就造成了变量数量和名称数量个数不等。我想大概是因为这个~

使用道具

报纸
weiqun890 在职认证  发表于 2013-1-29 22:43:32 |只看作者 |坛友微信交流群
remlus 发表于 2013-1-29 19:31
佩服做空间计量的人。
没办法的办法,呵呵

使用道具

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

使用道具

7
胖胖和瘦瘦 发表于 2013-1-29 23:08:56 |只看作者 |坛友微信交流群
weiqun890 发表于 2013-1-29 22:50
谢谢!我尝试一下!还有一个问题就是权重矩阵的行列式为0,这个是不是也会影响,若是的话,您知道怎么修正 ...
(╯﹏╰)b  这个不清楚了,不过我想应该不会有影响的。   我也是初学者,咱们还得多向那些牛人学习请教啊!

使用道具

8
weiqun890 在职认证  发表于 2013-2-19 17:02:51 来自手机 |只看作者 |坛友微信交流群
有哪位大侠知道这个问题怎么解决吗

使用道具

9
johnstill 发表于 2013-2-20 11:09:56 |只看作者 |坛友微信交流群
看了你的代码,无语,这种错误你也会犯?我不知道你是用Elhorst或Lesage教授的代码,但是起码二人现在都对空间面板模型的估计方法都进行了改进,ols方法严格的假设不太符合数据本身要求!另外,补充一句,你模型中存在估计错误在所难免,我只能提示你错误出在以下三行,具体修改你找本Matlab资料吧:
y=A(:,[1]);
x=A(:,[2:11]);  
xconstant=ones(N*T,1);
最后,郑重提醒您:最好将估计方法换成GMM或系统GMM估计,那样,上面三句就不用改动了,只要重新写一个GMM程序啦!

使用道具

10
彭艳琼 发表于 2013-3-29 14:04:43 |只看作者 |坛友微信交流群
楼主,您好!想向您请教空间计量的问题,已加您QQ。谢谢!

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-25 16:17