# matlab运行空间计量操作速成-经管之家官网！

>>

## TOP热门关键词

 免费学术公开课,扫码加入

3. %
4. % SAR, SEM, SAC, SDM, SDEM and GNS models. Every time this file is run
5. %
6. T=30; % number of time periods
7. N=46; % number of regions
8. % row-normalize W
9. W=normw(W1); % function of LeSage
10. y=A(:,[3]); % column number in the data matrix that corresponds to the dependent variable
11. x=A(:,[4,6]); % column numbers in the data matrix that correspond to the independent variables
12. for t=1:T
13. t1=(t-1)*N+1;t2=t*N;
14. wx(t1:t2,:)=W*x(t1:t2,:);
15. end
16. xconstant=ones(N*T,1);
17. [nobs K]=size(x); %size返回的是行和列
18. et=ones(T,1);
19. en=ones(N,1);
20. %
21. % All models include spatial and time period fixed effects
22. %
23. % ----------------------------------------------------------------------------------------
24. % No spatial interaction effects
25. model=3;
26. [ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,x,N,T,model);
27. results=ols(ywith,xwith);
28. vnames=strvcat('logcit','logp','logy'); % should be changed if x is changed
29. prt_reg(results,vnames);
30. intercept=mean(y)-mean(x)*results.beta;
31. sfe=meanny-meannx*results.beta-kron(en,intercept);
32. tfe=meanty-meantx*results.beta-kron(et,intercept);
33. yme = y - mean(y);
34. ent=ones(N*T,1);
35. error=y-kron(tfe,en)-kron(et,sfe)-x*results.beta-kron(ent,intercept);
36. rsqr1 = error'*error;
37. rsqr2 = yme'*yme;
38. FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effects
39. sige=results.sige*((nobs-K)/nobs);
40. loglik=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid

41. % ----------------------------------------------------------------------------------------
42. % Spatial lag model
43. info.lflag=0; % required for exact results
44. info.model=3;
45. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
46. % New routines to calculate effects estimates
47. results=sar_panel_FE(y,x,W,T,info);
48. vnames=strvcat('logcit','logp','logy');
49. % Print out coefficient estimates
50. prt_sp(results,vnames,1);
51. % Print out effects estimates
52. spat_model=0;
53. direct_indirect_effects_estimates(results,W,spat_model);
54. % panel_effects_sar(results,vnames,W);

55. % ----------------------------------------------------------------------------------------
56. % Spatial error model
57. info.lflag=0; % required for exact results
58. info.model=3;
59. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
60. % New routines to calculate effects estimates
61. results=sem_panel_FE(y,x,W,T,info);
62. % Print out coefficient estimates
63. prt_sp(results,vnames,1);

64. % ----------------------------------------------------------------------------------------
65. % Model with exogenous interaction effects
66. model=3;
67. [ywith,xwith,meanny,meannx,meanty,meantx]=demean(y,[x wx],N,T,model);
68. results=ols(ywith,xwith);
69. vnames=strvcat('logcit','logp','logy','W*logp','W*logy');
70. prt_reg(results,vnames);
71. intercept=mean(y)-mean([x wx])*results.beta;
72. sfe=meanny-meannx*results.beta-kron(en,intercept);
73. tfe=meanty-meantx*results.beta-kron(et,intercept);
74. yme = y - mean(y);
75. ent=ones(N*T,1);
76. error=y-kron(tfe,en)-kron(et,sfe)-[x wx]*results.beta-kron(ent,intercept);
77. rsqr1 = error'*error;
78. rsqr2 = yme'*yme;
79. FE_rsqr2 = 1.0 - rsqr1/rsqr2 % r-squared including fixed effects
80. sige=results.sige*((nobs-K)/nobs);
81. loglik=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid
82. % ----------------------------------------------------------------------------------------
83. % Spatial Durbin model
84. info.lflag=0; % required for exact results
85. info.model=3;
86. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
87. info.bc=1;
88. % New routines to calculate effects estimates
89. results=sar_panel_FE(y,[x wx],W,T,info);
90. % Print out coefficient estimates
91. prt_sp(results,vnames,1);
92. % Print out effects estimates
93. spat_model=1;
94. direct_indirect_effects_estimates(results,W,spat_model);
95. %panel_effects_sdm(results,vnames,W);

96. % ----------------------------------------------------------------------------------------
97. % Spatial Durbin error model
98. info.lflag=0; % required for exact results
99. info.model=3;
100. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
101. info.bc=1;
102. % New routines to calculate effects estimates
103. results=sem_panel_FE(y,[x wx],W,T,info);
104. % Print out coefficient estimates
105. prt_sp(results,vnames,1);

106. % ----------------------------------------------------------------------------------------
107. % SAC / SARAR / Clifford-Ord/ Kelejian-Prucha model
108. info.lflag=0; % required for exact results
109. info.model=3;
110. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
111. info.bc=1;
112. results=sac_panel_FE(y,x,W,T,info);
113. vnames=strvcat('logcit','logp','logy');
114. prt_spnew(results,vnames,1);
115. % Print out effects estimates
116. spat_model=0;
117. direct_indirect_effects_estimates(results,W,spat_model);
118. % ----------------------------------------------------------------------------------------
119. % Full model
120. info.model=3;
121. info.fe=0; % Do not print intercept and fixed effects; use info.fe=1 to turn on
122. info.bc=1;
123. results=sac_panel_FE(y,[x wx],W,T,info);
124. vnames=strvcat('logcit','logp','logy','W*logp','W*logy');
125. prt_spnew(results,vnames,1);
126. % Print out effects estimates
127. spat_model=1;
128. direct_indirect_effects_estimates(results,W,spat_model);

Pual Elhost的主页
http://www.regroningen.nl/elhorst/software.shtml
James Lesage 个人主页
http://www.spatial-econometrics.com/
kelley pace个人网站
http://www.spatial-statistics.com/
Donald J. Lacombe个人主页
http://community.wvu.edu/~djlacombe/
Journal of Statistical Software杂志首页
http://www.jstatsoft.org/
「经管之家」APP：经管人学习、答疑、交友，就上经管之家！

## 人气文章

#### 本文标题：matlab运行空间计量操作速成

1.凡人大经济论坛-经管之家转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责；
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性，不作出任何保证或承若；
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。