楼主: lvgod
14556 21

[问答] 请教matlab做空间面板如何做LM和robust-LM检验? [推广有奖]

11
kjfx2014 学生认证  发表于 2015-5-4 10:08:22 |只看作者 |坛友微信交流群
同问。我也出现同样的问题,老是说我出现奇异矩阵,或是出现“0”除现象。可能是我的权重矩阵有几列为零的缘故。可问题是,我不能随便修改权重矩阵呀,另外也不知道怎么修改最后运行出来的结果恰好不是奇异矩阵?

使用道具

12
kjfx2014 学生认证  发表于 2015-5-4 10:09:33 |只看作者 |坛友微信交流群
期盼有高人回复和指导呀!在此先多谢了

使用道具

13
kjfx2014 学生认证  发表于 2015-5-4 10:11:30 |只看作者 |坛友微信交流群
还有,我看见很多地方说,可以使用pinv这个函数求伪逆矩阵,也就是说即使计算中出现奇异矩阵也是可以正常运行的。可我不知道在程序中哪里可以加上?

使用道具

14
kjfx2014 学生认证  发表于 2015-5-4 10:14:18 |只看作者 |坛友微信交流群
这里是代码:
clear all;

A=wk1read('cigardemo.wk1',1,0);
W1=wk1read('Spat-Sym-US.wk1');
% Dataset downloaded from www.wiley.co.uk/baltagi/
% Spatial weights matrix constructed by Elhorst
%
% written by: J.Paul Elhorst summer 2008
% University of Groningen
% Department of Economics
% 9700AV Groningen
% the Netherlands
% j.p.elhorst@rug.nl
%
% REFERENCES: 
% Elhorst JP (2009) Spatial Panel Data Models. In Fischer MM, Getis A (Eds.) 
% Handbook of Applied Spatial Analysis, Ch. C.2. Springer: Berlin Heidelberg New York.
%
% dimensions of the problem
T=6; % number of time periods
N=46; % number of regions
% row-normalize W
W=normw(W1); % function of LeSage
y=A(:,3); % column number in the data matrix that corresponds to the dependent variable
x=A(:,[4,5,6]); % 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=char('logcit','intercept','logp','logpn','logy');
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=char('logcit','logp','logpn','logy'); % 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=char('logcit','logp','logpn','logy'); % should be changed if x is changed
prt_reg(results,vnames);
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

使用道具

15
kjfx2014 学生认证  发表于 2015-5-4 10:15:28 |只看作者 |坛友微信交流群
出错的语句都是在每个model下的最后一个语句:LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests

使用道具

16
konger 发表于 2016-4-14 08:19:16 来自手机 |只看作者 |坛友微信交流群
楼主,请问你的问题解决了吗,我最近也在做一个类似的课题,然而并没有用过MATLAB ,能给我发一份实例那个参考一下么,谢谢。邮箱:669230052@qq.com

使用道具

17
onlyayy 发表于 2016-9-1 18:36:17 |只看作者 |坛友微信交流群
很想请问下 为何我做出来的robust的LM值比LM值更大呀
LM test no spatial lag, probability          =  152.1242,   0.0000
robust LM test no spatial lag, probability   =  168.0992,   0.0000
LM test no spatial error, probability        =   74.6188,   0.0000
robust LM test no spatial error, probability =   90.5938,   0.0000

使用道具

18
shiminfeng 发表于 2017-4-26 16:39:22 |只看作者 |坛友微信交流群
您好,向您请教:目前为止MATLAB可以做空间面板莫兰散点图吗?谢谢呀

使用道具

19
百变星空1227 发表于 2017-4-26 20:01:41 |只看作者 |坛友微信交流群
木美紫凝 发表于 2015-1-27 16:21
这个我也不清楚,各年的空间效应我是用作业文件夹下面的全国MORAN I程序进行的检验,把数据放里面计算的每一 ...
你好,我下载的空间面板的MATLAB程序中也没有作业那个文件夹,不知能否发一份给我?谢谢~~~邮箱1095043515@qq.com

使用道具

20
charley1347 发表于 2018-3-27 00:21:58 |只看作者 |坛友微信交流群
lvgod 发表于 2015-1-26 16:47
这里是代码:
clear all;
你好请问一下您的MATLAB版本是什么版本?为什么我的显示wk1read函数无法运行?谢谢~

使用道具

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

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

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

GMT+8, 2024-4-26 21:32