空间面板 matlab,有人能帮我做一个空间面板分析吗

A=xlsread('mat.xlsx');

W1=xlsread('weight.xlsx');

T=14; % number of time periods

N=31; % 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]); % column numbers in the data matrix that correspond to the independent variables

for t=1:T

t1=(t-1)*N+1;t2=t*N;

wx(t1:t2,:)=W*x(t1:t2,:);

end

xconstant=ones(N*T,1);

[nobs K]=size(x);

% ----------------------------------------------------------------------------------------

% No fixed effects + spatially lagged dependent variable

info.lflag=0; % required for exact results

info.model=0;

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,[xconstant x],W,T,info);

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

% 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);

% ----------------------------------------------------------------------------------------

% No fixed effects + spatially lagged dependent variable + spatially

% independent variables

info.lflag=0; % required for exact results

info.model=0;

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,[xconstant x wx],W,T,info);

vnames=strvcat('y','intercept','x1','x2','W*x1','W*x2')

% 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);

% ----------------------------------------------------------------------------------------

% Spatial fixed effects + spatially lagged dependent variable

info.lflag=0; % required for exact results

info.model=1;

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('y','x1','x2');

% 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);

% ----------------------------------------------------------------------------------------

% Spatial fixed effects + spatially lagged dependent variable + spatially independent variables

info.lflag=0; % required for exact results

info.model=1;

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('y','x1','x2''W*x1','W*x2');

% 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);

% ----------------------------------------------------------------------------------------

% 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 wx],W,T,info);

vnames=strvcat('y','x1','x2''W*x1','W*x2');

% 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);

% ----------------------------------------------------------------------------------------

% 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('y','x1','x2');

% 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);

% ----------------------------------------------------------------------------------------

% 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('y','x1','x2','W*x1','W*x2');

% 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);

% 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

% 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

% Wald test spatial Durbin model against spatial error model

我这段代码运行之后提示说:未定义与 'struct' 类型的输入参数相对应的函数 'prt_sp'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值