# Stata: 单位根检验就这么轻松

Stata 连享会   主页 || 视频 || 推文

E-mail: m.xu@fs.de

## 4.1 ADF 检验

``````. dfuller yrwd2, trend

Dickey-Fuller test for unit root       Number of obs = 149

--------- Interpolated Dickey-Fuller ---------
Test     1% Critical  5% Critical   10% Critical
Statistic       Value        Value          Value
----------------------------------------------------------
Z(t)     -2.664        -4.024       -3.443         -3.143
----------------------------------------------------------
MacKinnon approximate p-value for Z(t) = 0.2511
``````

``````. dfuller yt, trend

Dickey-Fuller test for unit root        Number of obs = 149

---------- Interpolated Dickey-Fuller ---------
Test      1% Critical   5% Critical  10% Critical
Statistic        Value          Value          Value
-----------------------------------------------------------
Z(t)     -5.328         -4.024        -3.443        -3.143
-----------------------------------------------------------
MacKinnon approximate p-value for Z(t) = 0.0000
``````

### 4.2 Phillips–Perron 检验

Phillips(1987)[^P1987] 和 Phillips and Perron(1988)[^P1988] 开发出这个检验主要是为了解决残差项中潜在的序列相关和异方差问题，其检验统计量的渐进分布和临界值与 ADF 检验相同。

### 4.3 GLS 去势的 ADF 检验

Elliott et al. (1996)[^E1996] 提出的 GLS-ADF 检验与 ADF 检验类似，只是在对模型 $\left(4\right)$ 进行估计之前，需要先对时间序列进行GLS回归。Elliott et al. (1996)[^E1996] 证明了这个检验比 ADF 检验表现更好。

``````. dfgls yrwd2, maxlag(4)

DF-GLS for yrwd2                            Number of obs = 145

DF-GLS tau   1% Critical  5% Critical  10% Critical
[lags]  Test Statistic     Value        Value         Value
---------------------------------------------------------------
4         -1.404        -3.520       -2.930        -2.643
3         -1.420        -3.520       -2.942        -2.654
2         -1.638        -3.520       -2.953        -2.664
1         -1.644        -3.520       -2.963        -2.673

Opt Lag (Ng-Perron seq t) = 0 [use maxlag(0)]
Min SC   =   3.31175 at lag  1 with RMSE  5.060941
Min MAIC =  3.295598 at lag  1 with RMSE  5.060941
``````

``````. dfgls yt, maxlag(4)

DF-GLS for yt                               Number of obs = 145

DF-GLS tau    1% Critical  5% Critical  10% Critical
[lags] Test Statistic      Value        Value         Value
---------------------------------------------------------------
4        -4.013         -3.520       -2.930        -2.643
3        -4.154         -3.520       -2.942        -2.654
2        -4.848         -3.520       -2.953        -2.664
1        -4.844         -3.520       -2.963        -2.673

Opt Lag (Ng-Perron seq t) = 0 [use maxlag(0)]
Min SC   =  3.302146 at lag  1 with RMSE  5.036697
Min MAIC =  3.638026 at lag  1 with RMSE  5.036697
``````

## 6. 附录

``````clear all
set seed 2016
local T = 200
set obs `T'
gen time = _n
label var time "Time"
tsset time
gen eps = rnormal(0,5)

/*Random walk*/
gen yrw = eps in 1
replace yrw = l.yrw + eps in 2/l

/*Random walk with drift*/
gen yrwd1 = 0.1 + eps in 1
replace yrwd1 = 0.1 + l.yrwd1 + eps in 2/l

/*Random walk with drift*/
gen yrwd2 = 1 + eps in 1
replace yrwd2 = 1 + l.yrwd2 + eps in 2/l

/*Stationary around a time trend model*/
gen yt = 0.5 + 0.1*time + eps in 1
replace yt = 0.5 + 0.1*time +0.8*l.yt+ eps in 2/l
drop in 1/50

tsline yrw yrwd1, title("Stochastic trend")          ///
legend(label(1 "Random walk")                ///
label(2 "Random walk with drift"))
tsline yt yrwd2,                                     ///
legend(label(1 "Deterministic time trend")   ///
label(2 "Random walk with drift"))           ///
title("Stochastic and deterministic trend")
``````

## 参考文献

[^P1987]:Phillips, P. C. B. 1987. Time series regression with a unit root. Econometrica 55: 277–301.

[^P1988]:Phillips, P. C. B., and P. Perron. 1988. Testing for a unit root in time series regression. Biometrika 75: 335–346.

[^H1994]:Hamilton, J. D. 1994. Time Series Analysis. Princeton: Princeton University Press.

[^E1996]:Elliott, G. R., T. J. Rothenberg, and J. H. Stock. 1996. Efficient tests for an autoregressive unit root. Econometrica 64: 813–836.

## 相关课程

http://lianxh.duanshu.com

### 课程一览

Stata数据清洗 游万海 直播, 2 小时，已上线

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

#### 关于我们

• Stata连享会 由中山大学连玉君老师团队创办，定期分享实证分析经验。直播间 有很多视频课程，可以随时观看。
• 连享会-主页知乎专栏，300+ 推文，实证分析不再抓狂。
• 公众号推文分类： 计量专题 | 分类推文 | 资源工具。推文分成 内生性 | 空间计量 | 时序面板 | 结果输出 | 交乘调节 五类，主流方法介绍一目了然：DID, RDD, IV, GMM, FE, Probit 等。
• 公众号关键词搜索/回复 功能已经上线。大家可以在公众号左下角点击键盘图标，输入简要关键词，以便快速呈现历史推文，获取工具软件和数据下载。常见关键词：`课程, 直播, 视频, 客服, 模型设定, 研究设计, stata, plus, 绘图, 编程, 面板, 论文重现, 可视化, RDD, DID, PSM, 合成控制法`

✏ 连享会学习群-常见问题解答汇总：
https://gitee.com/arlionn/WD