代码相关原文见帖:
【分享学习】空间面板向量自回归Sp P-var论文数据及代码
https://bbs.pinggu.org/forum.php?mod=viewthread&tid=10906475&from^^uid=11374248
以下为sp pvar代码解读
- *==============
- * Main Results
- *==============
- ***1. estimate the model and run two stability tests (time and spatial stability)
- pvarstablecivo //time stability
- display("=======================")
- //computation for spatial stability (specific for two endogenous variables and one lag only)
- display("the largest modulus of time-spatial roots is") //spatial and time roots
- scalar bigN=e(N_clust) // N_clust short for Number of clusters 聚类变量的个数;scalar定义一个标量,用以后续计算
- matrix B=e(b) // e(b)是coefficient vector,回归后保存结果系数列向量的矩阵e(b)为B
- scalar smalln=wordcount(e(depvar)) // wordcount计算内生变量的个数:2
- matrix A1=[B[1,"lights:L.lights".."lights:L.odas"] \ B[1,"odas:L.lights".."odas:L.odas"]] // 定义一个名为A1的2行2列的矩阵,逗号作为列的分隔,反斜线作为行的分隔,注意反斜线的前后要加空格,否则斜线和数字挨到一起stata不识别;选取的是时间滞后项
- matrix colnames A1= lig aid // 定义列名,分别为lig、aid
- matrix rownames A1= lig aid // 定义行名,分别为lig、aid
- 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,能够发现矩阵行标题上有多一行带冒号的文字,此命令用于定义冒号前的名称,输入空格或者没有内容则消除带冒号的标题行
- matrix S=[B[1,"lights:lights36".."lights:odas36"] \ B[1,"odas:lights36".."odas:odas36"]] // 选取的是空间滞后项
- matrix colnames S= lig aid
- matrix rownames S= lig aid
- matrix coleq S= " "
- spatwmat using "CC36" , name(CC36) // CC36是The contiguity matrix (either 1 if
- districts i and j are neighbors or 0 if j is not a neighbor of i, with a diagonal
- of zeros by construction),是空间矩阵,原为dta文件,通过spatwmat 转为矩阵保存
- matrix I_n=I(smalln) // 生成smalln维的单位矩阵(smalln代表一个标量)


雷达卡




京公网安备 11010802022788号







