楼主: Lee_iris
4286 1

[学习心得] stata matrix相关命令学习笔记 [推广有奖]

已卖:1253份资源

教授

47%

还不是VIP/贵宾

-

威望
0
论坛币
1167 个
通用积分
1196.5565
学术水平
36 点
热心指数
43 点
信用等级
35 点
经验
14504 点
帖子
893
精华
0
在线时间
1517 小时
注册时间
2019-3-5
最后登录
2026-1-4

楼主
Lee_iris 在职认证  学生认证  发表于 2022-2-15 13:42:52 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
共同学习,如有问题欢迎批评指正。
代码相关原文见帖:
【分享学习】空间面板向量自回归Sp P-var论文数据及代码
https://bbs.pinggu.org/forum.php?mod=viewthread&tid=10906475&from^^uid=11374248


以下为sp pvar代码解读
  1. *==============
  2. * Main Results
  3. *==============

  4. ***1. estimate the model and run two stability tests (time and spatial stability)

  5. pvarstablecivo //time stability

  6. display("=======================")
  7. //computation for spatial stability (specific for two endogenous variables and one lag only)
  8. display("the largest modulus of time-spatial roots is") //spatial and time roots

  9. scalar bigN=e(N_clust) // N_clust short for Number of clusters  聚类变量的个数;scalar定义一个标量,用以后续计算
  10. matrix B=e(b) // e(b)是coefficient vector,回归后保存结果系数列向量的矩阵e(b)为B  
  11. scalar smalln=wordcount(e(depvar)) // wordcount计算内生变量的个数:2


  12. matrix A1=[B[1,"lights:L.lights".."lights:L.odas"] \ B[1,"odas:L.lights".."odas:L.odas"]] // 定义一个名为A1的2行2列的矩阵,逗号作为列的分隔,反斜线作为行的分隔,注意反斜线的前后要加空格,否则斜线和数字挨到一起stata不识别;选取的是时间滞后项

  13. matrix colnames A1= lig aid // 定义列名,分别为lig、aid
  14. matrix rownames A1= lig aid // 定义行名,分别为lig、aid
  15. matrix coleq A1= " " // matrix coleq: Reset column names and interpret simple names as equation names. matrix roweq and coleq also reset the row and column names of an already existing matrix, but if a simple name (a name without a colon) is specified, it is interpreted as an equation name.在执行这一步之前可以执行:matrix list A1,能够发现矩阵行标题上有多一行带冒号的文字,此命令用于定义冒号前的名称,输入空格或者没有内容则消除带冒号的标题行

  16. matrix S=[B[1,"lights:lights36".."lights:odas36"] \ B[1,"odas:lights36".."odas:odas36"]] // 选取的是空间滞后项
  17. matrix colnames S= lig aid
  18. matrix rownames S= lig aid
  19. matrix coleq S= " "

  20. spatwmat using "CC36" , name(CC36) // CC36是The contiguity matrix (either 1 if
  21. districts i and j are neighbors or 0 if j is not a neighbor of i, with a diagonal
  22. of zeros by construction),是空间矩阵,原为dta文件,通过spatwmat 转为矩阵保存

  23. matrix I_n=I(smalln) // 生成smalln维的单位矩阵(smalln代表一个标量)
复制代码





二维码

扫码加我 拉你入群

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

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

关键词:matrix Stata 学习笔记 tata Mat

沙发
Lee_iris 在职认证  学生认证  发表于 2022-2-15 20:50:49
  1. ***2. run the autocorrelation and cross-sectional dependence checks
  2. //these pvars show that the residuals of the (1,1) specification are autocorrelated, while the baseline has cleaner residuals

  3. qui pvarcivo lights odas if ash==1 | dark==1, lags(1) instlag(1) gmmopts(two  winitial(i) wmatrix(cl id)) vce(cle id) spatial(lights36 odas36) exog(rains) ivspt(rains36) overid sig2 td
  4. gen res1=res00lights // pvarcivo中的option sig2 produces a series of residuals resid00‘var’ for each of the endogenous variables ‘var’ of the model
  5. gen res2=res00odas
  6. pvarcivo res1 res2 if ash==1 | dark==1, lags(1) instlag(1) gmmopts(two  winitial(i) wmatrix(cl id)) vce(cle id) overid

  7. qui pvarcivo lights odas if ash==1 | dark==1, lags(1) instlag(2/3) gmmopts(two  winitial(i) wmatrix(cl id)) vce(cle id) spatial(lights36 odas36) exog(rains) ivspt(rains36) overid sig2 td
  8. replace res1= res00lights
  9. replace res2= res00odas
  10. pvarcivo res1 res2 if ash==1 | dark==1, lags(1) instlag(1) gmmopts(two  winitial(i) wmatrix(cl id)) vce(cle id) overid

  11. //estiamte the dynamic panel version of the model with xtabond2; also show relative importance of subsets of IVs; see Section 4.1 of the paper
复制代码


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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-2-2 22:41