楼主: celon081211
22131 39

[问答] 求教 空间面板matlab 程序中后缀为wk1的文件怎么打开? [推广有奖]

  • 0关注
  • 1粉丝

硕士生

17%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
784 点
帖子
52
精华
0
在线时间
167 小时
注册时间
2008-8-6
最后登录
2019-11-8

楼主
celon081211 发表于 2011-6-28 18:10:13 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
空间面板matlab程序中,后缀为wk1的文件, 我打不开 , 网上有人介绍了 一些能打开它的软件,  我下了,  但还是打不开 。我想打开看看 ,才能知道空间面板数据输入的方式。有人打开过吗?能不能帮我下。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:MATLAB atlab matla 空间面板 Mat MATLAB 程序 面板 空间 后缀

本帖被以下文库推荐

沙发
tulipsliu 在职认证  发表于 2011-6-28 19:02:48
不用在下载什么其他软件的,MATLAB 有一个读文件的命令可以打开这个格式的文件。
.wk1 格式的文件是 lotus 软件的。在spatial econometrics 里,一些数据是以这个格式存储。
  1. A=wk1read('cigarette.wk1',1,0); % data set with T=30
  2. W1=wk1read('Spat-Sym-US.wk1');
  3. % Dataset downloaded from www.wiley.co.uk/baltagi/
  4. % Spatial weights matrix constructed by Elhorst
  5. %
  6. % written by: J.Paul Elhorst summer 2010
  7. % University of Groningen
  8. % Department of Economics
  9. % 9700AV Groningen
  10. % the Netherlands
  11. % j.p.elhorst@rug.nl
  12. %
  13. % REFERENCES:
  14. % Elhorst JP (2010) Matlab Software for Spatial Panels. Under review.
  15. %
  16. % Elhorst JP (2010) Spatial Panel Data Models. In Fischer MM, Getis A (Eds.)
  17. % Handbook of Applied Spatial Analysis, Ch. C.2. Springer: Berlin Heidelberg New York.
  18. %
  19. % dimensions of the problem
  20. T=30; % number of time periods
  21. N=46; % number of regions
  22. % row-normalize W
  23. W=normw(W1); % function of LeSage
  24. y=A(:,3); % column number in the data matrix that corresponds to the dependent variable
  25. x=A(:,[4,6]); % column numbers in the data matrix that correspond to the independent variables
  26. xconstant=ones(N*T,1);
  27. [nobs K]=size(x);
  28. %%
  29. % ols estimation
  30. results=ols(y,[xconstant x]);
  31. vnames=char('logcit','intercept','logp','logy');
  32. prt_reg(results,vnames,1);
  33. sige=results.sige*((nobs-K)/nobs);
  34. loglikols=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid;

  35. % The (robust)LM tests developed by Elhorst

  36. LMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests

  37. % The lm tests developed by Donald Lacombe
  38. % see http://www.rri.wvu.edu/lacombe/~lacombe.htm

  39. lm1=lmlag_panel(y,[xconstant x],W);
  40. prt_tests(lm1);

  41. lm2=lmerror_panel(y,[xconstant x],W);
  42. prt_tests(lm2);

  43. lm3=lmlag_robust_panel(y,[xconstant x],W);
  44. prt_tests(lm3);

  45. lm4=lmerror_robust_panel(y,[xconstant x],W);
  46. prt_tests(lm4);

  47. %%
  48. % spatial fixed effects + (robust) LM tests for spatial lag and spatial error model
  49. % fixed effects, within estimator
  50. % demeaning of the y and x variables
  51. model=1;
  52. [ywith,xwith,meanny,meannx,~,meantx]=demean(y,x,N,T,model);
  53. results=ols(ywith,xwith);
  54. vnames=char('logcit','logp','logy'); % should be changed if x is changed
  55. prt_reg(results,vnames);
  56. sfe=meanny-meannx*results.beta; % including the constant term
  57. yme = y - mean(y);
  58. et=ones(T,1);
  59. error=y-kron(et,sfe)-x*results.beta;
  60. rsqr1 = error'*error;
  61. rsqr2 = yme'*yme;
  62. FE_rsqr2 = 1.0 - rsqr1/rsqr2; % r-squared including fixed effects
  63. sige=results.sige*((nobs-K)/nobs);
  64. logliksfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid;
  65. LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests

  66. lm1=lmlag_panel(ywith,xwith,W);
  67. prt_tests(lm1);

  68. lm2=lmerror_panel(ywith,xwith,W);
  69. prt_tests(lm2);

  70. lm3=lmlag_robust_panel(ywith,xwith,W);
  71. prt_tests(lm3);

  72. lm4=lmerror_robust_panel(ywith,xwith,W);
  73. prt_tests(lm4);
  74. %%
  75. % time-period fixed effects + (robust) LM tests for spatial lag and spatial error model
  76. % fixed effects, within estimator
  77. % demeaning of the y and x variables
  78. model=2;
  79. [ywith,xwith,~,~,meanty,meantx]=demean(y,x,N,T,model);
  80. results=ols(ywith,xwith);
  81. vnames=char('logcit','logp','logy'); % should be changed if x is changed
  82. prt_reg(results,vnames);
  83. tfe=meanty-meantx*results.beta; % including the constant term
  84. yme = y - mean(y);
  85. en=ones(N,1);
  86. error=y-kron(tfe,en)-x*results.beta;
  87. rsqr1 = error'*error;
  88. rsqr2 = yme'*yme;
  89. FE_rsqr2 = 1.0 - rsqr1/rsqr2; % r-squared including fixed effects
  90. sige=results.sige*((nobs-K)/nobs);
  91. logliktfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid;
  92. LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests

  93. lm1=lmlag_panel(ywith,xwith,W);
  94. prt_tests(lm1);

  95. lm2=lmerror_panel(ywith,xwith,W);
  96. prt_tests(lm2);

  97. lm3=lmlag_robust_panel(ywith,xwith,W);
  98. prt_tests(lm3);

  99. lm4=lmerror_robust_panel(ywith,xwith,W);
  100. prt_tests(lm4);
  101. %%
  102. % spatial and time period fixed effects + (robust) LM tests for spatial lag and spatial error model
  103. % fixed effects, within estimator
  104. % demeaning of the y and x variables
  105. model=3;
  106. [ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);
  107. results=ols(ywith,xwith);
  108. vnames=char('logcit','logp','logy'); % should be changed if x is changed
  109. prt_reg(results,vnames);
  110. intercept=mean(y)-mean(x)*results.beta;
  111. sfe=meanny-meannx*results.beta-kron(en,intercept);
  112. tfe=meanty-meantx*results.beta-kron(et,intercept);
  113. yme = y - mean(y);
  114. ent=ones(N*T,1);
  115. error=y-kron(tfe,en)-kron(et,sfe)-x*results.beta-kron(ent,intercept);
  116. rsqr1 = error'*error;
  117. rsqr2 = yme'*yme;
  118. FE_rsqr2 = 1.0 - rsqr1/rsqr2; % r-squared including fixed effects
  119. sige=results.sige*((nobs-K)/nobs);
  120. loglikstfe=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid;

  121. LMsarsem_panel(results,W,ywith,xwith); % (Robust) LM tests

  122. lm1=lmlag_panel(ywith,xwith,W);
  123. prt_tests(lm1);

  124. lm2=lmerror_panel(ywith,xwith,W);
  125. prt_tests(lm2);

  126. lm3=lmlag_robust_panel(ywith,xwith,W);
  127. prt_tests(lm3);

  128. lm4=lmerror_robust_panel(ywith,xwith,W);
  129. prt_tests(lm4);
  130. %%
  131. % Tests for the joint significance of spatial and/or time-period fixed effects
  132. LR=-2*(logliktfe-loglikstfe);
  133. dof=N;
  134. probability=1-chis_prb(LR,dof);
  135. % Note: probability > 0.05 implies rejection of spatial fixed effects
  136. fprintf(1,'LR-test joint significance spatial fixed effects, degrees of freedom and probability = %9.4f,%6d,%9.4f \n',LR,dof,probability);
  137. LR=-2*(logliksfe-loglikstfe);
  138. dof=T;
  139. probability=1-chis_prb(LR,dof);
  140. % Note: probability > 0.05 implies rejection of spatial fixed effects
  141. fprintf(1,'LR-test joint significance time-periode fixed effects, degrees of freedom and probability = %9.4f,%6d,%9.4f \n',LR,dof,probability);
复制代码


这个是Elhorst 的空间面板程序。第一行,第二行。都是读入数据。用的命令是A=wk1read('cigarette.wk1',1,0);,有这个专用的函数。
不过,MATLAB升级后提示,以后的更高版本将不支持这个格式的文件,不提供读这个格式文件的命令。
已有 1 人评分经验 论坛币 学术水平 热心指数 信用等级 收起 理由
Sunknownay + 100 + 8 + 1 + 1 + 1 热心帮助其他会员

总评分: 经验 + 100  论坛币 + 8  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

劳动经济学

藤椅
celon081211 发表于 2011-6-28 19:50:07
懂了  谢谢tulipsliu

板凳
celon081211 发表于 2011-6-28 20:42:17
2# tulipsliu      运行程序后  结果中没有显示46各地区个体固定效应的值  我想在程序结果中显示各地区个体固定效应的值  在程序中哪些地方需要改一下?

报纸
tulipsliu 在职认证  发表于 2011-6-28 22:37:03
Pooled model with spatially lagged dependent variable, spatial and time period fixed effects
Dependent Variable =           logcit
R-squared          =    0.9017   
corr-squared       =    0.4000   
sigma^2            =    0.0052
Nobs,Nvar,#FE      =   1380,     5,    79  
log-likelihood     =        1691.3765
# of iterations    =      1   
min and max rho    =   -1.0000,   1.0000
total time in secs =    0.2600
time for optimiz   =    0.0420
time for lndet     =    0.0820
time for t-stats   =    0.0180
No lndet approximation used
***************************************************************
Variable        Coefficient  Asymptot t-stat    z-probability
logp              -1.000929       -24.357098         0.000000
logy               0.602499        10.275488         0.000000
W*logp             0.098477         1.199756         0.230234
W*logy            -0.315374        -3.946235         0.000079
W*dep.var.         0.268601         8.405988         0.000000

    direct    t-stat   indirect    t-stat   total    t-stat

ans =

   -1.0123  -24.4405   -0.2158   -2.3248   -1.2282  -11.6947
    0.5905   10.1725   -0.1974   -2.1148    0.3931    4.4148

Direct        Coefficient           t-stat           t-prob         lower 05         upper 95
logp            -1.011059       -24.649478         0.000000        -1.092786        -0.932449
logy             0.592300        10.276515         0.000000         0.475786         0.704131

Indirect      Coefficient           t-stat           t-prob         lower 05         upper 95
logp            -0.219392        -2.230008         0.030668        -0.410712        -0.044342
logy            -0.195287        -2.090119         0.042163        -0.377556        -0.009990

Total         Coefficient           t-stat           t-prob         lower 05         upper 95
logp            -1.230451       -11.447830         0.000000        -1.447621        -1.032379
logy             0.397013         4.578789         0.000036         0.226768         0.569779


Wald_spatial_lag =

   18.3474


prob_spatial_lag =

  1.0373e-004


LR_spatial_lag =

   15.7775


prob_spatial_lag =

  3.7494e-004


Wald_spatial_error =

    8.0949


prob_spatial_error =

    0.0175


LR_spatial_error =

    8.2759


prob_spatial_error =

    0.0160
劳动经济学

地板
tulipsliu 在职认证  发表于 2011-6-28 22:42:01
4# celon081211
我很少做空间计量模型,一直都是按照金融学的要求,做金融建模的,也不知道这个是你要的程序不。
我贴上程序给你吧。上面的结果就是用这个程序做的。
  1. % Demonstration file for Elhorst Panel Data code
  2. %
  3. % Dataset downloaded from www.wiley.co.uk/baltagi/
  4. % Spatial weights matrix constructed by Elhorst
  5. %
  6. % written by: J.Paul Elhorst summer 2010
  7. % University of Groningen
  8. % Department of Economics
  9. % 9700AV Groningen
  10. % the Netherlands
  11. % j.p.elhorst@rug.nl
  12. %
  13. % REFERENCE:
  14. % Elhorst JP (2010) Matlab Software for Spatial Panels. Under review.
  15. %
  16. % Elhorst JP (2010) Spatial Panel Data Models. In Fischer MM, Getis A (Eds.)
  17. % Handbook of Applied Spatial Analysis, Ch. C.2. Springer: Berlin Heidelberg New York.
  18. %
  19. % New:

  20. % 1) Direct/Indirect effect esimates of the explanatory variables
  21. % LeSage JP, Pace RK (2009) Introduction to Spatial Econometrics. Boca Raton, Taylor & Francis Group.
  22. % routine direct_indirect_effects_estimates(results,W,spat_model) is written by J.P. Elhorst
  23. % routines panel_effects_sar(results,vnames,W) and panel_effects_sar(results,vnames,W)
  24. % are written and made available by D. Lacombe
  25. % User may use both routines (note: results are slightly different from each other since they are based on draws from a distrobution
  26. % or choose one particular routine. If N is large, user should choose
  27. % Lacombe's routines, since this one is much more efficient computationally

  28. % 2) Bias correction of coefficient estimates
  29. % Lee Lf, Yu J. (2010) Estimation of spatial autoregressive models with
  30. % fixed effects, Journal of Econometrics 154: 165-185.

  31. % 3) Selection framework to determine which spatial panel data model best
  32. % describes the data.

  33. % dimensions of the problem
  34. A=wk1read('cigarette.wk1',1,0);
  35. W1=wk1read('Spat-Sym-US.wk1');
  36. T=30; % number of time periods
  37. N=46; % number of regions
  38. % row-normalize W
  39. W=normw(W1); % function of LeSage
  40. y=A(:,[3]); % column number in the data matrix that corresponds to the dependent variable
  41. x=A(:,[4,6]); % column numbers in the data matrix that correspond to the independent variables
  42. for t=1:T
  43.     t1=(t-1)*N+1;t2=t*N;
  44.     wx(t1:t2,:)=W*x(t1:t2,:);
  45. end
  46. xconstant=ones(N*T,1);
  47. [nobs K]=size(x);
  48. % ----------------------------------------------------------------------------------------
  49. % No fixed effects + spatially lagged dependent variable
  50. info.lflag=0; % required for exact results
  51. info.model=0;
  52. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  53. % New routines to calculate effects estimates
  54. results=sar_panel_FE(y,[xconstant x],W,T,info);
  55. vnames=char('logcit','intercept','logp','logy');
  56. % Print out coefficient estimates
  57. prt_sp(results,vnames,1);
  58. % Print out effects estimates
  59. spat_model=0;
  60. direct_indirect_effects_estimates(results,W,spat_model);
  61. panel_effects_sar(results,vnames,W);
  62. % ----------------------------------------------------------------------------------------
  63. % No fixed effects + spatially lagged dependent variable + spatially
  64. % independent variables
  65. info.lflag=0; % required for exact results
  66. info.model=0;
  67. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  68. % New routines to calculate effects estimates
  69. results=sar_panel_FE(y,[xconstant x wx],W,T,info);
  70. vnames=char('logcit','intercept','logp','logy','W*logp','W*logy');
  71. % Print out coefficient estimates
  72. prt_sp(results,vnames,1);
  73. % Print out effects estimates
  74. spat_model=1;
  75. direct_indirect_effects_estimates(results,W,spat_model);
  76. panel_effects_sdm(results,vnames,W);
  77. % ----------------------------------------------------------------------------------------
  78. % Spatial fixed effects + spatially lagged dependent variable
  79. info.lflag=0; % required for exact results
  80. info.model=1;
  81. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  82. % New routines to calculate effects estimates
  83. results=sar_panel_FE(y,x,W,T,info);
  84. vnames=char('logcit','logp','logy');
  85. % Print out coefficient estimates
  86. prt_sp(results,vnames,1);
  87. % Print out effects estimates
  88. spat_model=0;
  89. direct_indirect_effects_estimates(results,W,spat_model);
  90. panel_effects_sar(results,vnames,W);
  91. % ----------------------------------------------------------------------------------------
  92. % Spatial fixed effects + spatially lagged dependent variable + spatially
  93. % independent variables
  94. info.lflag=0; % required for exact results
  95. info.model=1;
  96. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  97. % New routines to calculate effects estimates
  98. results=sar_panel_FE(y,[x wx],W,T,info);
  99. vnames=char('logcit','logp','logy','W*logp','W*logy');
  100. % Print out coefficient estimates
  101. prt_sp(results,vnames,1);
  102. % Print out effects estimates
  103. spat_model=1;
  104. direct_indirect_effects_estimates(results,W,spat_model);
  105. panel_effects_sdm(results,vnames,W);
  106. % ----------------------------------------------------------------------------------------
  107. % Time period fixed effects + spatially lagged dependent variable
  108. info.lflag=0; % required for exact results
  109. info.model=2;
  110. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  111. % New routines to calculate effects estimates
  112. results=sar_panel_FE(y,x,W,T,info);
  113. vnames=char('logcit','logp','logy');
  114. % Print out coefficient estimates
  115. prt_sp(results,vnames,1);
  116. % Print out effects estimates
  117. spat_model=0;
  118. direct_indirect_effects_estimates(results,W,spat_model);
  119. panel_effects_sar(results,vnames,W);
  120. % ----------------------------------------------------------------------------------------
  121. % Time period fixed effects + spatially lagged dependent variable + spatially
  122. % independent variables
  123. info.lflag=0; % required for exact results
  124. info.model=2;
  125. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  126. % New routines to calculate effects estimates
  127. results=sar_panel_FE(y,[x wx],W,T,info);
  128. vnames=char('logcit','logp','logy','W*logp','W*logy');
  129. % Print out coefficient estimates
  130. prt_sp(results,vnames,1);
  131. % Print out effects estimates
  132. spat_model=1;
  133. direct_indirect_effects_estimates(results,W,spat_model);
  134. panel_effects_sdm(results,vnames,W);
  135. % ----------------------------------------------------------------------------------------
  136. % Spatial and time period fixed effects + spatially lagged dependent variable
  137. info.lflag=0; % required for exact results
  138. info.model=3;
  139. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  140. % New routines to calculate effects estimates
  141. results=sar_panel_FE(y,x,W,T,info);
  142. vnames=char('logcit','logp','logy');
  143. % Print out coefficient estimates
  144. prt_sp(results,vnames,1);
  145. % Print out effects estimates
  146. spat_model=0;
  147. direct_indirect_effects_estimates(results,W,spat_model);
  148. panel_effects_sar(results,vnames,W);
  149. % ----------------------------------------------------------------------------------------
  150. % Spatial and time period fixed effects + spatially lagged dependent variable + spatially
  151. % independent variables
  152. % No bias correction
  153. info.bc=0;
  154. info.lflag=0; % required for exact results
  155. info.model=3;
  156. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  157. % New routines to calculate effects estimates
  158. results=sar_panel_FE(y,[x wx],W,T,info);
  159. vnames=char('logcit','logp','logy','W*logp','W*logy');
  160. % Print out coefficient estimates
  161. prt_sp(results,vnames,1);
  162. % Print out effects estimates
  163. spat_model=1;
  164. direct_indirect_effects_estimates(results,W,spat_model);
  165. panel_effects_sdm(results,vnames,W);
  166. % Wald test for spatial Durbin model against spatial lag model
  167. btemp=results.parm;
  168. varcov=results.cov;
  169. Rafg=zeros(K,2*K+2);
  170. for k=1:K
  171.     Rafg(k,K+k)=1; % R(1,3)=0 and R(2,4)=0;
  172. end
  173. Wald_spatial_lag=(Rafg*btemp)'*inv(Rafg*varcov*Rafg')*Rafg*btemp
  174. prob_spatial_lag=1-chis_cdf (Wald_spatial_lag, K) % probability greater than 0.05 points to insignificance
  175. % LR test spatial Durbin model against spatial lag model (requires
  176. % estimation results of the spatial lag model to be available)
  177. resultssar=sar_panel_FE(y,x,W,T,info);
  178. LR_spatial_lag=-2*(resultssar.lik-results.lik)
  179. prob_spatial_lag=1-chis_cdf (LR_spatial_lag,K) % probability greater than 0.05 points to insignificance
  180. % Wald test spatial Durbin model against spatial error model
  181. R=zeros(K,1);
  182. for k=1:K
  183.     R(k)=btemp(2*K+1)*btemp(k)+btemp(K+k); % k changed in 1, 7/12/2010
  184. %   R(1)=btemp(5)*btemp(1)+btemp(3);
  185. %   R(2)=btemp(5)*btemp(2)+btemp(4);
  186. end
  187. Rafg=zeros(K,2*K+2);
  188. for k=1:K
  189.     Rafg(k,k)    =btemp(2*K+1); % k changed in 1, 7/12/2010
  190.     Rafg(k,K+k)  =1;
  191.     Rafg(k,2*K+1)=btemp(k);
  192. %   Rafg(1,1)=btemp(5);Rafg(1,3)=1;Rafg(1,5)=btemp(1);
  193. %   Rafg(2,2)=btemp(5);Rafg(2,4)=1;Rafg(2,5)=btemp(2);
  194. end   
  195. Wald_spatial_error=R'*inv(Rafg*varcov*Rafg')*R
  196. prob_spatial_error=1-chis_cdf (Wald_spatial_error,K) % probability greater than 0.05 points to insignificance
  197. % LR test spatial Durbin model against spatial error model (requires
  198. % estimation results of the spatial error model to be available
  199. resultssem=sem_panel_FE(y,x,W,T,info);
  200. LR_spatial_error=-2*(resultssem.lik-results.lik)
  201. prob_spatial_error=1-chis_cdf (LR_spatial_error,K) % probability greater than 0.05 points to insignificance
复制代码
劳动经济学

7
tulipsliu 在职认证  发表于 2011-6-28 22:43:18
  1. % ----------------------------------------------------------------------------------------
  2. % Spatial and time period fixed effects + spatially lagged dependent variable + spatially
  3. % independent variables
  4. info.lflag=0; % required for exact results
  5. info.model=3;
  6. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
  7. info.bc=1;
  8. % New routines to calculate effects estimates
  9. results=sar_panel_FE(y,[x wx],W,T,info);
  10. vnames=char('logcit','logp','logy','W*logp','W*logy');
  11. % Print out coefficient estimates
  12. prt_sp(results,vnames,1);
  13. % Print out effects estimates
  14. spat_model=1;
  15. direct_indirect_effects_estimates(results,W,spat_model);
  16. panel_effects_sdm(results,vnames,W);
  17. % Wald test for spatial lag model
  18. btemp=results.parm;
  19. varcov=results.cov;
  20. Rafg=zeros(K,2*K+2);
  21. for k=1:K
  22.     Rafg(k,K+k)=1; % R(1,3)=0 and R(2,4)=0;
  23. end
  24. Wald_spatial_lag=(Rafg*btemp)'*inv(Rafg*varcov*Rafg')*Rafg*btemp
  25. prob_spatial_lag= 1-chis_cdf (Wald_spatial_lag, K) % probability greater than 0.05 points to insignificance
  26. % LR test spatial Durbin model against spatial lag model (requires
  27. % estimation results of the spatial lag model to be available)
  28. resultssar=sar_panel_FE(y,x,W,T,info);
  29. LR_spatial_lag=-2*(resultssar.lik-results.lik)
  30. prob_spatial_lag=1-chis_cdf (LR_spatial_lag,K) % probability greater than 0.05 points to insignificance
  31. % Wald test for spatial error model
  32. R=zeros(K,1);
  33. for k=1:K
  34.     R(k)=btemp(2*K+1)*btemp(k)+btemp(K+k); % k changed in 1, 7/12/2010
  35. %   R(1)=btemp(5)*btemp(1)+btemp(3);
  36. %   R(2)=btemp(5)*btemp(2)+btemp(4);
  37. end
  38. Rafg=zeros(K,2*K+2);
  39. for k=1:K
  40.     Rafg(k,k)    =btemp(2*K+1); % k changed in 1, 7/12/2010
  41.     Rafg(k,K+k)  =1;
  42.     Rafg(k,2*K+1)=btemp(k);
  43. %   Rafg(1,1)=btemp(5);Rafg(1,3)=1;Rafg(1,5)=btemp(1);
  44. %   Rafg(2,2)=btemp(5);Rafg(2,4)=1;Rafg(2,5)=btemp(2);
  45. end   
  46. Wald_spatial_error=R'*inv(Rafg*varcov*Rafg')*R
  47. prob_spatial_error= 1-chis_cdf (Wald_spatial_error,K) % probability greater than 0.05 points to insignificance
  48. % LR test spatial Durbin model against spatial error model (requires
  49. % estimation results of the spatial error model to be available
  50. resultssem=sem_panel_FE(y,x,W,T,info);
  51. LR_spatial_error=-2*(resultssem.lik-results.lik)
  52. prob_spatial_error=1-chis_cdf (LR_spatial_error,K) % probability greater than 0.05 points to insignificance
  53. % needed for Hausman test later on
  54. logliklag=results.lik;
  55. blagfe=results.parm(1:end-1);
  56. covblagfe=results.cov(1:end-1,1:end-1);
  57. %
  58. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% random effects estimator by ML %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  59. %
  60. % Spatial random effects and time period fixed effects + spatially lagged dependent variable + spatially
  61. % independent variables
  62. [ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,[x wx],N,T,2); % 2=time dummies
  63. info.model=1;
  64. results=sar_panel_RE(ywith,xwith,W,T,info);
  65. prt_sp(results,vnames,1);
  66. % Print out effects estimates
  67. spat_model=1;
  68. direct_indirect_effects_estimates(results,W,spat_model);
  69. panel_effects_sdm(results,vnames,W);
  70. % Wald test for spatial lag model
  71. btemp=results.parm(1:2*K+2);
  72. varcov=results.cov(1:2*K+2,1:2*K+2);
  73. Rafg=zeros(K,2*K+2);
  74. for k=1:K
  75.     Rafg(k,K+k)=1; % R(1,3)=0 and R(2,4)=0;
  76. end
  77. Wald_spatial_lag=(Rafg*btemp)'*inv(Rafg*varcov*Rafg')*Rafg*btemp
  78. prob_spatial_lag= 1-chis_cdf (Wald_spatial_lag, K) % probability greater than 0.05 points to insignificance
  79. % Wald test for spatial error model
  80. R=zeros(K,1);
  81. for k=1:K
  82.     R(k)=btemp(2*K+1)*btemp(k)+btemp(K+k); % k changed in 1, 7/12/2010
  83. %   R(1)=btemp(5)*btemp(1)+btemp(3);
  84. %   R(2)=btemp(5)*btemp(2)+btemp(4);
  85. end
  86. Rafg=zeros(K,2*K+2);
  87. for k=1:K
  88.     Rafg(k,k)    =btemp(2*K+1); % k changed in 1, 7/12/2010
  89.     Rafg(k,K+k)  =1;
  90.     Rafg(k,2*K+1)=btemp(k);
  91. %   Rafg(1,1)=btemp(5);Rafg(1,3)=1;Rafg(1,5)=btemp(1);
  92. %   Rafg(2,2)=btemp(5);Rafg(2,4)=1;Rafg(2,5)=btemp(2);
  93. end   
  94. Wald_spatial_error=R'*inv(Rafg*varcov*Rafg')*R
  95. prob_spatial_error= 1-chis_cdf (Wald_spatial_error,K) % probability greater than 0.05 points to insignificance
  96. % needed for Hausman test later on
  97. logliklagre=results.lik;
  98. blagre=results.parm(1:end-2);
  99. covblagre=results.cov(1:end-2,1:end-2);
  100. % ----------------------------------------------------------------------------------------
  101. % Hausman test FE versus RE
  102. hausman=(blagfe-blagre)'*inv(covblagre-covblagfe)*(blagfe-blagre);
  103. dof=length(blagfe);
  104. probability=1-chis_prb(abs(hausman),dof);
  105. % Note: probability < 0.025 implies rejection of random effects model in favor of fixed effects model
  106. % Use 0.025, since it is a one-sided test
  107. fprintf(1,'Hausman test-statistic, degrees of freedom and probability = %9.4f,%6d,%9.4f \n',abs(hausman),dof,probability);
复制代码
劳动经济学

8
tulipsliu 在职认证  发表于 2011-6-28 22:47:02

这两端代码都是同一个程序的,你把他们放在同一个文件夹里。
因为上传代码,超过10000字就发不了。
就截成两端了。

你把今晚我上传的这两段程序合并在一起用。


哦哦,哈哈,刚才那个一个demo里的。
这里还有一个更恰当的demo,发布代码太占屏幕,我保存为.txt 的文本文件了。你在MATLAB里新建一个空白文件,复制我上传的.txt文件的全部内容,粘贴进去就可以了。

劳动经济学

9
celon081211 发表于 2011-6-29 20:02:38
谢谢tulipsliu  :)  
我再试试

10
zcyouwillwin 发表于 2011-7-28 17:24:11
看您是高手,能请教您一个问题么,您在调用prt_sp函数时没有报错是么?我在调用时结果出现说是在prt_sp.m中没有定义norm_prb这个函数,难道我下载的空间面板工具箱中程序有错么?您能传一份完整的面板工具箱给我么?真的非常感谢,我可以给您论坛币,尽最大努力,拜托了,我都耗了半个月了,谢谢您!

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 20:39