




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1.excel與MATLAB鏈接:Excel:選項(xiàng)加載項(xiàng)COM加載項(xiàng)轉(zhuǎn)到?jīng)]有勾選項(xiàng) 2. MATLAB安裝目錄中尋找toolboxexlink點(diǎn)擊,啟用宏 E:MATLABtoolboxexlink然后,Excel中就出現(xiàn)MATLAB工具(注意Excel中的數(shù)據(jù):)3.啟動(dòng)matlab(1) 點(diǎn)擊start MATLAB(2) senddata to matlab ,并對(duì)變量矩陣變量進(jìn)行命名(注意:選取變量為數(shù)值,不包括各變量)(data表中數(shù)據(jù)進(jìn)行命名)(空間權(quán)重進(jìn)行命名)(3) 導(dǎo)入MATLAB中的兩個(gè)矩陣變量就可以看見4.將elhorst和jplv7兩個(gè)程序文件夾復(fù)制到MATLAB安裝目
2、錄的toolbox文件夾5.設(shè)置路徑:6.輸入程序,得出結(jié)果T=30; N=46; W=normw(W1); y=A(:,3); x=A(:,4,6); xconstant=ones(N*T,1);nobs K=size(x);results=ols(y,xconstant x);vnames=strvcat('logcit','intercept','logp','logy');prt_reg(results,vnames,1);sige=results.sige*(nobs-K)/nobs);loglikols=-nobs/2
3、*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid% The (robust)LM tests developed by ElhorstLMsarsem_panel(results,W,y,xconstant x); % (Robust) LM tests解釋每一行分別表示:該面板數(shù)據(jù)的時(shí)期數(shù)為30(T=30),該面板數(shù)據(jù)有30個(gè)地區(qū)(N=30),將空間權(quán)重矩陣標(biāo)準(zhǔn)化(W=normw(w1)),將名為A(以矩陣形式出現(xiàn)在MATLABA中)的變量的第3列數(shù)據(jù)定義為被解釋變量y,將名為A的變量的第4、5、6列數(shù)據(jù)定義為解釋變量矩陣
4、x,定義一個(gè)有N*T行,1列的全1矩陣,該矩陣名為:xconstant,(ones即為全1矩陣)說(shuō)明解釋變量矩陣x的大?。河衝obs行,K列。(size為描述矩陣的大?。?。附錄:靜態(tài)面板空間計(jì)量經(jīng)濟(jì)學(xué)一、OLS靜態(tài)面板編程1、普通面板編程T=30; N=46; W=normw(W1); y=A(:,3); x=A(:,4,6); xconstant=ones(N*T,1);nobs K=size(x);results=ols(y,xconstant x);vnames=strvcat('logcit','intercept','logp',
5、9;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% The (robust)LM tests developed by ElhorstLMsarsem_panel(results,W,y,xconstant x); % (Robust) LM tests2、空間固定OLS (spatial-fixed effects)T=30; N=46; W=no
6、rmw(W1); y=A(:,3); x=A(:,4,6); xconstant=ones(N*T,1);nobs K=size(x);model=1;ywith,xwith,meanny,meannx,meanty,meantx=demean(y,x,N,T,model);results=ols(ywith,xwith);vnames=strvcat('logcit','logp','logy'); % should be changed if x is changedprt_reg(results,vnames);sfe=meanny-mea
7、nnx*results.beta; % including the constant termyme = y - mean(y);et=ones(T,1);error=y-kron(et,sfe)-x*results.beta;rsqr1 = error'*error;rsqr2 = yme'*yme;FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effectssige=results.sige*(nobs-K)/nobs);logliksfe=-nobs/2*log(2*pi*sige)-1/(2*sige)
8、*results.resid'*results.residLMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests3、時(shí)期固定OLS(time-period fixed effects)T=30; N=46; W=normw(W1); y=A(:,3); x=A(:,4,6); xconstant=ones(N*T,1);nobs K=size(x);model=2;ywith,xwith,meanny,meannx,meanty,meantx=demean(y,x,N,T,model);results=ols(ywith,x
9、with);vnames=strvcat('logcit','logp','logy'); % should be changed if x is changedprt_reg(results,vnames);tfe=meanty-meantx*results.beta; % including the constant termyme = y - mean(y);en=ones(N,1);error=y-kron(tfe,en)-x*results.beta;rsqr1 = error'*error;rsqr2 = yme'*y
10、me;FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effectssige=results.sige*(nobs-K)/nobs);logliktfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.residLMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests4、空間與時(shí)間雙固定模型T=30; N=46; W=normw(W1); y=A(:,3); x=A(:,4,6); xconsta
11、nt=ones(N*T,1);nobs K=size(x);model=3;ywith,xwith,meanny,meannx,meanty,meantx=demean(y,x,N,T,model);results=ols(ywith,xwith);vnames=strvcat('logcit','logp','logy'); % should be changed if x is changedprt_reg(results,vnames)en=ones(N,1);et=ones(T,1);intercept=mean(y)-mean(x)*r
12、esults.beta; sfe=meanny-meannx*results.beta-kron(en,intercept);tfe=meanty-meantx*results.beta-kron(et,intercept);yme = y - mean(y);ent=ones(N*T,1);error=y-kron(tfe,en)-kron(et,sfe)-x*results.beta-kron(ent,intercept);rsqr1 = error'*error;rsqr2 = yme'*yme;FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squar
13、ed including fixed effectssige=results.sige*(nobs-K)/nobs);loglikstfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.residLMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests二、靜態(tài)面板SAR模型1、無(wú)固定效應(yīng)(No fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2
14、=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0; info.model=0;info.fe=0; results=sar_panel_FE(y,xconstant x,W,T,info); vnames=strvcat('logcit','intercept','logp','logy');prt_spnew(results,vnames,1)% Print out effects estimatesspat_m
15、odel=0;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sar(results,vnames,W);2、空間固定效應(yīng)(Spatial fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0;info.model=1;inf
16、o.fe=0; results=sar_panel_FE(y,x,W,T,info); vnames=strvcat('logcit','logp','logy');prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=0;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sar(results,vnames,W);3、時(shí)點(diǎn)固定效應(yīng)(Time period fixed effec
17、ts)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0; % required for exact resultsinfo.model=2;info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sar_panel_FE(y
18、,x,W,T,info); vnames=strvcat('logcit','logp','logy');prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=0;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sar(results,vnames,W);4、雙固定效應(yīng)(Spatial and time period fixed effects)T=30; N=46; W=no
19、rmw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0; % required for exact resultsinfo.model=3;info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sar_panel_FE(y,x,W,T,info); vname
20、s=strvcat('logcit','logp','logy');prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=0;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sar(results,vnames,W);三、靜態(tài)面板SDM模型1、無(wú)固定效應(yīng)(No fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6);
21、for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0; info.model=0;info.fe=0; results=sar_panel_FE(y,xconstant x wx,W,T,info); vnames=strvcat('logcit','intercept','logp','logy','W*logp','W*logy');
22、prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sdm(results,vnames,W);2、空間固定效應(yīng)(Spatial fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxcon
23、stant=ones(N*T,1);nobs K=size(x);info.lflag=0; % required for exact resultsinfo.model=1;info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sar_panel_FE(y,x wx,W,T,info); vnames=strvcat('logcit','logp','logy','W*logp','W*logy'
24、;);prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sdm(results,vnames,W);3、時(shí)點(diǎn)固定效應(yīng)(Time period fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);
25、endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0; % required for exact resultsinfo.model=2;info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on% New routines to calculate effects estimatesresults=sar_panel_FE(y,x wx,W,T,info); vnames=strvcat('logcit','logp&
26、#39;,'logy','W*logp','W*logy');% Print out coefficient estimatesprt_spnew(results,vnames,1)% Print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sdm(results,vnames,W)4、雙固定效應(yīng)(Spatial and time period fixed effects)T=30;
27、N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.bc=0;info.lflag=0; % required for exact resultsinfo.model=3;info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sar_panel_FE(
28、y,x wx,W,T,info); vnames=strvcat('logcit','logp','logy','W*logp','W*logy');prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sdm(results,vnames,W)wald test spatial lag% Wa
29、ld test for spatial Durbin model against spatial lag modelbtemp=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;endWald_spatial_lag=(Rafg*btemp)'*inv(Rafg*varcov*Rafg')*Rafg*btempprob_spatial_lag=1-chis_cdf (Wald_spatial_lag, K)wald test s
30、patial error% Wald test spatial Durbin model against spatial error modelR=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);endRafg=zeros(K,2*K+2);for k=1:K Rafg(k,k) =btemp(2*K+1); % k changed i
31、n 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')*Rprob_spatial_error=1-chis_cdf (Wald_spatial_error,K)LR test spatial lagresultssar=sa
32、r_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) LR test spatial errorresultssem=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) 5、空間隨機(jī)效應(yīng)與時(shí)點(diǎn)固定效應(yīng)模型T=30;
33、 N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);ywith,xwith,meanny,meannx,meanty,meantx=demean(y,x wx,N,T,2); % 2=time dummiesinfo.model=1;results=sar_panel_RE(ywith,xwith,W,T,info); prt_spnew(results,vnames,1)sp
34、at_model=1;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sdm(results,vnames,W)wald test spatial lagbtemp=results.parm(1:2*K+2);varcov=results.cov(1:2*K+2,1:2*K+2);Rafg=zeros(K,2*K+2);for k=1:K Rafg(k,K+k)=1; % R(1,3)=0 and R(2,4)=0;endWald_spatial_lag=(Rafg*btemp)'*inv(Ra
35、fg*varcov*Rafg')*Rafg*btempprob_spatial_lag= 1-chis_cdf (Wald_spatial_lag, K) wald test spatial errorR=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);endRafg=zeros(K,2*K+2);for k=1:K Rafg(
36、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')*Rprob_spatial_error= 1-chis_cdf (Wald_spatial_error,
37、K) LR test spatial lagresultssar=sar_panel_RE(ywith,xwith(:,1:K),W,T,info); LR_spatial_lag=-2*(resultssar.lik-results.lik)prob_spatial_lag=1-chis_cdf (LR_spatial_lag,K) LR test spatial errorresultssem=sem_panel_RE(ywith,xwith(:,1:K),W,T,info); LR_spatial_error=-2*(resultssem.lik-results.lik)prob_spa
38、tial_error=1-chis_cdf (LR_spatial_error,K)四、靜態(tài)面板SEM模型1、無(wú)固定效應(yīng)(No fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0; info.model=0;info.fe=0; results=sem_panel_FE(y,xconstant x,W,T,info
39、); vnames=strvcat('logcit','intercept','logp','logy');prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=0;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sar(results,vnames,W);2、空間固定效應(yīng)(Spatial fixed effects)T=30; N=46; W=normw(W1
40、);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0;info.model=1;info.fe=0; results=sem_panel_FE(y,x,W,T,info); vnames=strvcat('logcit','logp','logy');prt_spnew(results,vnames,1)% Print out effect
41、s estimatesspat_model=0;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sar(results,vnames,W);3、時(shí)點(diǎn)固定效應(yīng)(Time period fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lfl
42、ag=0; % required for exact resultsinfo.model=2;info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sem_panel_FE(y,x,W,T,info); vnames=strvcat('logcit','logp','logy');prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=0;direct
43、_indirect_effects_estimates(results,W,spat_model);panel_effects_sar(results,vnames,W);4、雙固定效應(yīng)(Spatial and time period fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0; % required fo
44、r exact resultsinfo.model=3;info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sem_panel_FE(y,x,W,T,info); vnames=strvcat('logcit','logp','logy');prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=0;direct_indirect_effects_e
45、stimates(results,W,spat_model);panel_effects_sar(results,vnames,W);五、靜態(tài)面板SDEM模型1、無(wú)固定效應(yīng)(No fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0; info.model=0;info.fe=0; results=sem_panel
46、_FE(y,xconstant x wx,W,T,info); vnames=strvcat('logcit','intercept','logp','logy','W*logp','W*logy');prt_spnew(results,vnames,1)% Print out effects estimatesspat_model=1;direct_indirect_effects_estimates(results,W,spat_model);panel_effects_sdm(results,
47、vnames,W);2、空間固定效應(yīng)(Spatial fixed effects)T=30; N=46; W=normw(W1);y=A(:,3);x=A(:,4,6); for t=1:T t1=(t-1)*N+1;t2=t*N; wx(t1:t2,:)=W*x(t1:t2,:);endxconstant=ones(N*T,1);nobs K=size(x);info.lflag=0; % required for exact resultsinfo.model=1;info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn onresults=sem_panel_FE(y,x wx,W,T,info
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 網(wǎng)絡(luò)直播內(nèi)容監(jiān)管服務(wù)補(bǔ)充協(xié)議書
- 企業(yè)高端禮儀培訓(xùn)師長(zhǎng)期聘用協(xié)議
- 動(dòng)脈瘤病人護(hù)理
- 肢體活動(dòng)障礙護(hù)理
- 初一常見傳染病預(yù)防要點(diǎn)
- 城鄉(xiāng)居民健康體檢工作規(guī)范與實(shí)施方案
- 數(shù)據(jù)統(tǒng)計(jì)分析流程圖培訓(xùn)
- 兒童骨折飲食護(hù)理
- 被害妄想護(hù)理措施
- 2025版高考物理一輪復(fù)習(xí)全程訓(xùn)練計(jì)劃課練36機(jī)械振動(dòng)機(jī)械波含解析
- 2024年中國(guó)成人心肌炎臨床診斷與治療指南解讀
- 倉(cāng)庫(kù)三級(jí)安全教育培訓(xùn)
- 焊接實(shí)訓(xùn)車間建設(shè)方案
- 英國(guó)默許開發(fā)權(quán)的發(fā)展歷程、體系構(gòu)建與成效分析
- 電商售前客服質(zhì)檢培訓(xùn)
- 2023電力調(diào)度控制中心設(shè)計(jì)導(dǎo)則第1部分:術(shù)語(yǔ)和定義
- 中國(guó)兒童川崎病診療循證指南(2023年)解讀課件
- 《狼圖騰》閱讀分享與深度解讀
- 國(guó)網(wǎng)公司合規(guī)管理
- 鉛冶煉行業(yè)清潔生產(chǎn)評(píng)價(jià)指標(biāo)體系 替代 HJ 512-2009 HJ 513-2009
- 玉盤二部合唱正譜
評(píng)論
0/150
提交評(píng)論