杜宾模型效应分解代码如下,
clear;
[A,name]=xlsread('alldata.xlsx');
W1=xlsread('weight.xlsx');
T=10; % number of time periods
N=31; % number of regions
% row-normalize W
w=normw(W1); % function of LeSage
y=A(:,[2]); % column number in the data matrix that corresponds to the dependent variable
x=A(:,[3,6,7,8]); % 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);
% ---------------------------------------------------------------------------------------
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
results=sar_panel_FE(y,[x wx],w,T,info);
vnames=strvcat('y','csm','inc','price','urban','w*csm','w*inc','w*price','w*urban' );
prt_spnew(results,vnames,1)
% Print out effects estimates
spat_model=1;
direct_indirect_effects_estimates(results,w,spat_model);
panel_effects_sdm(results,vnames,w); 运行结果如下:
effect_separate_sdm
Pooled model with spatially lagged dependent variable and spatial fixed effects
Dependent Variable = y
R-squared = 0.9408
corr-squared = 0.9238
sigma^2 = 0.0300
Nobs,Nvar,#FE = 310, 9, 39
log-likelihood = 75.723476
# of iterations = 1
min and max rho = -1.0000, 1.0000
total time in secs = 0.1730
time for optimiz = 0.0060
time for lndet = 0.0130
time for t-stats = 0.0120
No lndet approximation used
***************************************************************
Variable Coefficient Asymptot t-stat z-probability
csm -0.132640 -4.087724 0.000044
inc 0.866986 13.211625 0.000000
price 2.067863 2.425411 0.015291
urban 1.479963 15.734717 0.000000
w*csm 0.121174 2.966329 0.003014
w*inc -0.311179 -2.487223 0.012874
w*price -0.965193 -0.468055 0.639745
w*urban -0.950597 -5.605412 0.000000
W*dep.var. 0.398999 4.711590 0.000002
Undefined function 'direct_indirect_effects_estimates' for input arguments of type 'struct'.
Error in effect_separate_sdm (line 26)
direct_indirect_effects_estimates(results,w,spat_model);