内生性检验 stata代码
时间: 2023-07-02 19:05:01 浏览: 4985
Stata中进行内生性检验通常使用的是ivregress或者ivreg2命令。
ivregress命令的语法为:
```stata
ivregress 2sls (dependent variable) (exogenous variables) (endogenous variables) (instruments)
```
其中,2sls表示使用两阶段最小二乘法进行估计,dependent variable表示因变量,exogenous variables表示外生变量,endogenous variables表示内生变量,instruments表示工具变量。
ivreg2命令的语法类似,但是支持更多的估计方法和统计量:
```stata
ivreg2 (dependent variable) (exogenous variables) (endogenous variables) (instruments), options
```
其中,options可以选择的参数包括:
- robust:进行异方差性检验
- cluster(cluster_variable):进行聚类标准误估计
- small:使用小样本标准误
- first:进行首步回归
- bw(n):使用窗口宽度为n的局部线性回归进行内生性检验
在使用ivregress或ivreg2命令时,需要注意以下几点:
1. 工具变量需要满足两个条件:与内生变量相关,与误差项不相关。
2. 内生性检验常用的统计量有Sargan test、Hansen J test和Anderson-Rubin test等。
3. 内生性检验需要使用外生变量和工具变量同时作为独立变量进行回归。
下面是一个简单的示例代码:
```stata
use "data.dta", clear
ivregress 2sls y x1 x2 (x3 x4)
ivreg2 y x1 x2 (x3 x4), bw(2)
```
其中,data.dta为数据文件,y、x1、x2、x3、x4为变量名。第一行使用ivregress进行内生性检验,第二行使用ivreg2进行内生性检验,并使用窗口宽度为2的局部线性回归。
阅读全文
相关推荐
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)