



版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、六步學會用matlab做空間計量回歸詳細步驟與matlab鏈接:excel:選項加載項com加載項轉到沒有勾選項 2. matlab安裝目錄中尋找toolboxexlink點擊,啟用宏 e:matlabtoolboxexlink然后,excel中就出現(xiàn)matlab工具(注意excel中的數據:)3.啟動matlab(1) 點擊start matlab(2) senddata to matlab ,并對變量矩陣變量進行命名(注意:選取變量為數值,不包括各變量)(data表中數據進行命名)(空間權重進行命名)(3) 導入matlab中的兩個矩陣變量就可以看見4.將elhorst和jplv7兩個程序
2、文件夾復制到matlab安裝目錄的toolbox文件夾5.設置路徑:6.輸入程序,得出結果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=*(nobs-k)/nobs);loglikols=-nob
3、s/2*log(2*pi*sige)-1/(2*sige)*'*% the (robust)lm tests developed by elhorstlmsarsem_panel(results,w,y,xconstant x); % (robust) lm tests解釋每一行分別表示:該面板數據的時期數為30(t=30),該面板數據有30個地區(qū)(n=30),將空間權重矩陣標準化(w=normw(w1)),將名為a(以矩陣形式出現(xiàn)在matlaba中)的變量的第3列數據定義為被解釋變量y,將名為a的變量的第4、5、6列數據定義為解釋變量矩陣x,定義一個有n*t行,1列的全1矩陣,該矩陣
4、名為:xconstant,(ones即為全1矩陣)說明解釋變量矩陣x的大小:有nobs行,k列。(size為描述矩陣的大小)。附錄:靜態(tài)面板空間計量經濟學一、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','logy');prt_reg(re
5、sults,vnames,1);sige=*(nobs-k)/nobs);loglikols=-nobs/2*log(2*pi*sige)-1/(2*sige)*'*% 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=normw(w1); y=a(:,3); x=a(:,4,6); xconstant=ones(n*t,1);nobs k=s
6、ize(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-meannx*; % including the constant termyme = y - mean(y);et=ones(
7、t,1);error=y-kron(et,sfe)-x*;rsqr1 = error'*error;rsqr2 = yme'*yme;fe_rsqr2 = - rsqr1/rsqr2 % r-squared including fixed effectssige=*(nobs-k)/nobs);logliksfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*'*lmsarsem_panel(results,w,ywith,xwith); % (robust) lm tests3、時期固定ols(time-period fixed effects)
8、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,xwith);vnames=strvcat('logcit','logp','logy'); % should be changed if x is changedprt_reg(results,vnames
9、);tfe=meanty-meantx*; % including the constant termyme = y - mean(y);en=ones(n,1);error=y-kron(tfe,en)-x*;rsqr1 = error'*error;rsqr2 = yme'*yme;fe_rsqr2 = - rsqr1/rsqr2 % r-squared including fixed effectssige=*(nobs-k)/nobs);logliktfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*'*lmsarsem_panel(re
10、sults,w,ywith,xwith); % (robust) lm tests4、空間與時間雙固定模型t=30; n=46; w=normw(w1); y=a(:,3); x=a(:,4,6); xconstant=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'); % sh
11、ould be changed if x is changedprt_reg(results,vnames)en=ones(n,1);et=ones(t,1);intercept=mean(y)-mean(x)*; sfe=meanny-meannx*(en,intercept);tfe=meanty-meantx*(et,intercept);yme = y - mean(y);ent=ones(n*t,1);error=y-kron(tfe,en)-kron(et,sfe)-x*(ent,intercept);rsqr1 = error'*error;rsqr2 = yme'
12、;*yme;fe_rsqr2 = - rsqr1/rsqr2 % r-squared including fixed effectssige=*(nobs-k)/nobs);loglikstfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*'*lmsarsem_panel(results,w,ywith,xwith); % (robust) lm tests二、靜態(tài)面板sar模型1、無固定效應(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;
13、t2=t*n; wx(t1:t2,:)=w*x(t1:t2,:);endxconstant=ones(n*t,1);nobs k=size(x);=0; =0;=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_model=0;direct_indirect_ef
14、fects_estimates(results,w,spat_model);panel_effects_sar(results,vnames,w);2、空間固定效應(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);=0;=1;=0; results=sar_panel_fe(y,x,w,t,info); vnames=s
15、trvcat('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、時點固定效應(time period fixed effects)t=30; n=46; w=normw(w1);y=a(:,3);x=a(:,4,6); for
16、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);=0; % required for exact results=2;=0; % do not print intercept and fixed effects; use =1 to turn onresults=sar_panel_fe(y,x,w,t,info); vnames=strvcat('logcit','logp','logy');prt_spnew
17、(results,vnames,1)% print out effects estimatesspat_model=0;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sar(results,vnames,w);4、雙固定效應(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,:);e
18、ndxconstant=ones(n*t,1);nobs k=size(x);=0; % required for exact results=3;=0; % do not print intercept and fixed effects; use =1 to turn onresults=sar_panel_fe(y,x,w,t,info); vnames=strvcat('logcit','logp','logy');prt_spnew(results,vnames,1)% print out effects estimatesspat_m
19、odel=0;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sar(results,vnames,w);三、靜態(tài)面板sdm模型1、無固定效應(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);=0; =0;=0; results=sar_p
20、anel_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(resu
21、lts,vnames,w);2、空間固定效應(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);=0; % required for exact results=1;=0; % do not print intercept and fixed effects; use =1 to turn onresults=sar_pa
22、nel_fe(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);3、時點固定效應(time per
23、iod 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);=0; % required for exact results=2;=0; % do not print intercept and fixed effects; use =1 to turn on% new routines to calculate effects estim
24、atesresults=sar_panel_fe(y,x wx,w,t,info); vnames=strvcat('logcit','logp','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);pa
25、nel_effects_sdm(results,vnames,w)4、雙固定效應(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);=0;=0; % required for exact results=3;=0; % do not print intercept and fixed eff
26、ects; use =1 to turn onresults=sar_panel_fe(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_sd
27、m(results,vnames,w)wald test spatial lag% wald test for spatial durbin model against spatial lag modelbtemp=;varcov=;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_spati
28、al_lag, k)wald test spatial 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(
29、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,k)lr test spa
30、tial lagresultssar=sar_panel_fe(y,x,w,t,info); lr_spatial_lag=-2* (lr_spatial_lag,k) lr test spatial errorresultssem=sem_panel_fe(y,x,w,t,info); lr_spatial_error=-2* (lr_spatial_error,k) 5、空間隨機效應與時點固定效應模型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:t
31、2,:);endxconstant=ones(n*t,1);nobs k=size(x);ywith,xwith,meanny,meannx,meanty,meantx=demean(y,x wx,n,t,2); % 2=time dummies=1;results=sar_panel_re(ywith,xwith,w,t,info); prt_spnew(results,vnames,1)spat_model=1;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sdm(results,vnames,w
32、)wald test spatial lagbtemp=(1:2*k+2);varcov=(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(rafg*varcov*rafg')*rafg*btempprob_spatial_lag= 1-chis_cdf (wald_spatial_lag, k) wald test spatial errorr=zeros(k,1);for k=
33、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 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
34、(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=sar_panel_re(ywith,xwith(:,1:k),w,t,info); lr_spatial_lag=-2* (lr_spatial_lag,k) lr test sp
35、atial errorresultssem=sem_panel_re(ywith,xwith(:,1:k),w,t,info); lr_spatial_error=-2* (lr_spatial_error,k)四、靜態(tài)面板sem模型1、無固定效應(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);=0; =0;=0; result
36、s=sem_panel_fe(y,xconstant x,w,t,info); 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、空間固定效應(spatial
37、 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);=0;=1;=0; results=sem_panel_fe(y,x,w,t,info); vnames=strvcat('logcit','logp','logy');prt_spnew(results,vnames,1)% print
38、out effects estimatesspat_model=0;direct_indirect_effects_estimates(results,w,spat_model);panel_effects_sar(results,vnames,w);3、時點固定效應(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
39、);=0; % required for exact results=2;=0; % do not print intercept and fixed effects; use =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_estima
40、tes(results,w,spat_model);panel_effects_sar(results,vnames,w);4、雙固定效應(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);=0; % required for exact results=3;=0; % do not pri
41、nt intercept and fixed effects; use =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_estimates(results,w,spat_model);panel_effects_sar(results,v
42、names,w);五、靜態(tài)面板sdem模型1、無固定效應(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);=0; =0;=0; results=sem_panel_fe(y,xconstant x wx,w,t,info); vnames=strvcat('logcit','intercept',&
43、#39;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);2、空間固定效應(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);=0; % required for exact results=1;=0; % do not print intercept and fixed effects; use =1 to turn onresults=sem_panel_fe(y,x wx,w,t,info); vnames=strvcat('logcit',
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 個人食堂承包協(xié)議書
- 單片機原理與應用練習題與參考答案
- 人防租賃轉讓合同范本
- 熱工基礎 模擬試題
- 萬年牢說課稿
- 一周學習總結
- 一防水合同范例
- 兼職定金合同范本
- 《荊棘鳥》讀書心得
- 制作甲方合同范本
- 口腔健康全身健康課件
- 2025年高考英語復習專項突破:讀后續(xù)寫提分寫作(解析版)
- 數字出版概論 課件 第一章 數字出版及其發(fā)展歷程
- Wonderware InTouch:報警與事件處理機制技術教程.Tex.header
- 一把手講安全課件:提升全員安全意識
- CNAS實驗室內審檢查表
- 華為全屋智能試題
- Unit 3 Food and Culture Reading and thinking閱讀課教學設計 2023-2024學年人教版高中英語選擇性必修第二冊
- 數學大觀 知到智慧樹網課答案
- 小兒白血病飲食
- 2024年杭州科技職業(yè)技術學院單招職業(yè)技能測試題庫及答案解析
評論
0/150
提交評論