# Stata：高度共线性情况下的IV估计-pariv

Stata连享会   主页 || 视频 || 推文 || 知乎 || Bilibili 站

New！ `lianxh` 命令发布了：

`. ssc install lianxh`

`. help lianxh`

⛳ Stata 系列推文：

Source：Young, A., 2022, Nearly collinear robust procedures for 2sls estimation, working paper. -PDF-

## 3. Stata 实操

``````ssc install pariv, replace
``````

``````pariv depvar (endovars = excludedlist) [includedinst] ///
[if] [in] [weight] [,options]
``````

• `depvar`：被解释变量
• `endovars`：内生变量
• `excludedinst`：工具变量
• `includedinst`：外生控制变量

`pariv` 可以分组地拟合被解释变量对内生变量的 2SLS，并且使用 `excludedinst` 作为 `endovars` 的工具变量。在参数估计之后，`pariv` 将会报告目标参数和标准差在各种分组、变量顺序、数据顺序等条件下的最大、最小值。下面的代码实例将会展示常用的 2SLS 估计方法 `ivregress` 得到的估计值对变量输入顺序的敏感性，以及 `pariv` 命令下得到的估计值在高度共线性下的稳健性。

``````. drop _all
. set seed 836
. quietly set obs 16
. gen double age = _n + 19
. gen double age2 = age^2
. gen double age3 = age^3
. gen double age4 = age^4
. gen double u = invnormal(uniform())
. gen double e = invnormal(uniform())
. gen double z = invnormal(uniform())
. gen double t = 10*z + u
. gen double y = t + u + e
``````

``````. ivregress 2sls y (t = z) age age2 age3 age4, robust

Instrumental variables 2SLS regression            Number of obs   =         16
Wald chi2(5)    =    2790.55
Prob > chi2     =     0.0000
R-squared       =     0.9893
Root MSE        =     1.0438
------------------------------------------------------------------------------
|               Robust
y | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
t |      0.926      0.055    16.72   0.000        0.817       1.034
age |   -264.610    142.618    -1.86   0.064     -544.136      14.916
age2 |     14.514      7.842     1.85   0.064       -0.856      29.883
age3 |     -0.350      0.189    -1.85   0.064       -0.721       0.021
age4 |      0.003      0.002     1.85   0.064       -0.000       0.006
_cons |   1788.965    960.297     1.86   0.062      -93.182    3671.112
------------------------------------------------------------------------------
Instrumented: t
Instruments: age age2 age3 age4 z

. ivregress 2sls y (t = z) age4 age age2 age3, robust

Instrumental variables 2SLS regression            Number of obs   =         16
Wald chi2(5)    =    1111.02
Prob > chi2     =     0.0000
R-squared       =     0.9747
Root MSE        =      1.609
------------------------------------------------------------------------------
|               Robust
y | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
t |      0.744      0.298     2.49   0.013        0.159       1.328
age4 |      0.010      0.010     0.93   0.355       -0.011       0.030
age |   -795.169    850.303    -0.94   0.350    -2461.732     871.393
age2 |     43.945     47.182     0.93   0.352      -48.531     136.421
age3 |     -1.067      1.150    -0.93   0.353       -3.320       1.186
_cons |   5332.821   5677.235     0.94   0.348    -5794.355   16459.998
------------------------------------------------------------------------------
Instrumented: t
Instruments: age4 age age2 age3 z
``````

``````. pariv y (t = z) age4 age age2 age3, robust reps(100)

Partitioned (collinear robust) 2SLS                 Number of obs  =         16
Estimates                Statistical Significance
coefficient  std. err.      |z|   P>|z|     [95% conf. interval]
-------------+-----------------------------------------------------------------
t |   .9395758  .04805926      19.55   0.000      .8453814    1.03377
age4 |  .00263474  .00141279      1.86   0.062    -.00013428  .00540376
age |  -223.5808   119.8144      1.87   0.062     -458.4128   11.25114
age2 |   12.23788   6.572025      1.86   0.063     -.6430484   25.11881
age3 |  -.2946544   .1582678      1.86   0.063     -.6048536  .01554485
_cons |   1514.899   808.6364      1.87   0.061     -69.99973   3099.797
-------------------------------------------------------------------------------
Range in 100 Permutations of Data and Variable Order
coefficients          standard errors
min        max          min        max
-------------+----------------------------------------------
t |   .9395758   .9395758    .04805926  .04805926
age4 |  .00263474  .00263474    .00141279  .00141279
age |  -223.5808  -223.5808     119.8144   119.8144
age2 |   12.23788   12.23788     6.572025   6.572025
age3 |  -.2946544  -.2946544     .1582678   .1582678
_cons |   1514.899   1514.899     808.6364   808.6364
-----------------------------------------------------------
Instrumented: t
Excluded instruments: z
Included instruments: age4 age age2 age3 _cons
Heteroskedasticity robust standard errors
Maximum R2 found in the regression of any one instrument on the others:  .99999998
``````

## 4. 相关推文

Note：产生如下推文列表的 Stata 命令为：
`lianxh 工具变量, m`

`ssc install lianxh, replace`

## 相关课程

### 最新课程-直播课

• Note: 部分课程的资料，PPT 等可以前往 连享会-直播课 主页查看，下载。

### 关于我们

• Stata连享会 由中山大学连玉君老师团队创办，定期分享实证分析经验。
• 连享会-主页知乎专栏，700+ 推文，实证分析不再抓狂。直播间 有很多视频课程，可以随时观看。
• 公众号关键词搜索/回复 功能已经上线。大家可以在公众号左下角点击键盘图标，输入简要关键词，以便快速呈现历史推文，获取工具软件和数据下载。常见关键词：`课程, 直播, 视频, 客服, 模型设定, 研究设计, stata, plus, 绘图, 编程, 面板, 论文重现, 可视化, RDD, DID, PSM, 合成控制法`

✏ 连享会-常见问题解答：
https://gitee.com/lianxh/Course/wikis

New！ `lianxh``songbl` 命令发布了：

`. ssc install lianxh`

`. help lianxh`