楼主: wangbbs
33493 118

MATLAB 空间计量模型的实现   [推广有奖]

11
wangbbs 发表于 2015-11-3 23:09:51 |只看作者 |坛友微信交流群
时间固定效应和空间滞后应变量
% Time period fixed effects + spatially lagged dependent variable
info.lflag=0; % required for exact results
info.model=2;
info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
% New routines to calculate effects estimates
results=sar_panel_FE(y,x,W,T,info);
vnames=strvcat('logcit','logp','logy');
% Print out coefficient estimates
prt_sp(results,vnames,1);
% Print out effects estimates
spat_model=0;
direct_indirect_effects_estimates(results,W,spat_model);
panel_effects_sar(results,vnames,W);

使用道具

12
wangbbs 发表于 2015-11-3 23:10:43 |只看作者 |坛友微信交流群
时间固定效应和空间滞后应变量和中间自变量
% Time period fixed effects + spatially lagged dependent variable + spatially
% independent variables
info.lflag=0; % required for exact results
info.model=2;
info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
% New routines to calculate effects estimates
results=sar_panel_FE(y,[x wx],W,T,info);
vnames=strvcat('logcit','logp','logy','W*logp','W*logy');
% Print out coefficient estimates
prt_sp(results,vnames,1);
% Print out effects estimates
spat_model=1;
direct_indirect_effects_estimates(results,W,spat_model);
panel_effects_sdm(results,vnames,W);

使用道具

13
wangbbs 发表于 2015-11-3 23:11:45 |只看作者 |坛友微信交流群
空间和时间双固定效应的空间滞后应变量
% Spatial and time period fixed effects + spatially lagged dependent variable
info.lflag=0; % required for exact results
info.model=3;
info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
% New routines to calculate effects estimates
results=sar_panel_FE(y,x,W,T,info);
vnames=strvcat('logcit','logp','logy');
% Print out coefficient estimates
prt_sp(results,vnames,1);
% Print out effects estimates
spat_model=0;
direct_indirect_effects_estimates(results,W,spat_model);
panel_effects_sar(results,vnames,W);

使用道具

14
wangbbs 发表于 2015-11-3 23:13:39 |只看作者 |坛友微信交流群
空间和时间双固定效应的空间滞后应变量和空间自变量(物贝叶斯纠正)
% Spatial and time period fixed effects + spatially lagged dependent variable + spatially
% independent variables
% No bias correction
info.bc=0;
info.lflag=0; % required for exact results
info.model=3;
info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
% New routines to calculate effects estimates
results=sar_panel_FE(y,[x wx],W,T,info);
vnames=strvcat('logcit','logp','logy','W*logp','W*logy');
% Print out coefficient estimates
prt_sp(results,vnames,1);
% Print out effects estimates
spat_model=1;
direct_indirect_effects_estimates(results,W,spat_model);
panel_effects_sdm(results,vnames,W);

使用道具

15
wangbbs 发表于 2015-11-3 23:14:30 |只看作者 |坛友微信交流群
Wald检验,空间杜宾模型
% Wald test for spatial Durbin model against spatial lag model
btemp=results.parm;
varcov=results.cov;
Rafg=zeros(K,2*K+2);
for k=1:K
    Rafg(k,K+k)=1; % R(1,3)=0 and R(2,4)=0;
end
Wald_spatial_lag=(Rafg*btemp)'*inv(Rafg*varcov*Rafg')*Rafg*btemp
prob_spatial_lag=1-chis_cdf (Wald_spatial_lag, K) % probability greater than 0.05 points to insignificance

使用道具

16
wangbbs 发表于 2015-11-3 23:15:44 |只看作者 |坛友微信交流群
空间杜宾模型的LR检验
% LR test spatial Durbin model against spatial lag model (requires
% estimation results of the spatial lag model to be available)
resultssar=sar_panel_FE(y,x,W,T,info);
LR_spatial_lag=-2*(resultssar.lik-results.lik)
prob_spatial_lag=1-chis_cdf (LR_spatial_lag,K) % probability greater than 0.05 points to insignificance

使用道具

17
wangbbs 发表于 2015-11-3 23:19:55 |只看作者 |坛友微信交流群
空间误差模型的Wald 检验,前面的那个是空间滞后模型的Wald 检验
% Wald test for spatial error model
R=zeros(K,1);
for k=1:K
    R(k)=btemp(2*K+1)*btemp(k)+btemp(K+k); % k changed in 1, 7/12/2010
%   R(1)=btemp(5)*btemp(1)+btemp(3);
%   R(2)=btemp(5)*btemp(2)+btemp(4);
end
Rafg=zeros(K,2*K+2);
for k=1:K
    Rafg(k,k)    =btemp(2*K+1); % k changed in 1, 7/12/2010
    Rafg(k,K+k)  =1;
    Rafg(k,2*K+1)=btemp(k);
%   Rafg(1,1)=btemp(5);Rafg(1,3)=1;Rafg(1,5)=btemp(1);
%   Rafg(2,2)=btemp(5);Rafg(2,4)=1;Rafg(2,5)=btemp(2);
end   
Wald_spatial_error=R'*inv(Rafg*varcov*Rafg')*R
prob_spatial_error= 1-chis_cdf (Wald_spatial_error,K) % probability greater than 0.05 points to insignificance

使用道具

18
wangbbs 发表于 2015-11-3 23:23:07 |只看作者 |坛友微信交流群
判断空间杜宾模型或者空间误差模型那个更合适解释数据的LR检验,前面的那个检验时针对空间杜宾和空间滞后模型选择的。
% LR test spatial Durbin model against spatial error model (requires
% estimation results of the spatial error model to be available
resultssem=sem_panel_FE(y,x,W,T,info);
LR_spatial_error=-2*(resultssem.lik-results.lik)
prob_spatial_error=1-chis_cdf (LR_spatial_error,K) % probability greater than 0.05 points to insignificance

使用道具

19
wangbbs 发表于 2015-11-3 23:26:53 |只看作者 |坛友微信交流群
最后是随机效应的检验。random effects estimator by ML

使用道具

20
wangbbs 发表于 2015-11-4 00:31:11 |只看作者 |坛友微信交流群
这个总程序大致可分成12个子程序段,每段程序是一个检验。并不是每个程序块都会运行,运行的程序块要通过检验来判断应该采用哪种模型。每个程序块中又包含不同的子程序检验。这些子程序检验结果将决定的你的主程序选择何种检验进行验证,并输出结果。所以不能光看主程序的检验还要看子程序的检验才行。

使用道具

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

本版微信群
加JingGuanBbs
拉您进交流群

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

GMT+8, 2024-5-4 13:20