Stata: 协整还是伪回归?

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

E-mail: m.xu@fs.de

Source: Ashish Rajbhandari[1]Cointegration or spurious regression?

Stata 连享会时间序列专题：

3. 例子

``````. use spurious, clear

. reg y x, nocons

Source |       SS           df       MS      Number of obs   =       100
-------------+----------------------------------   F(1, 99)        =      6.20
Model |  63.4507871         1  63.4507871   Prob > F        =    0.0144
Residual |  1013.32308        99  10.2355867   R-squared       =    0.0589
-------------+----------------------------------   Adj R-squared   =    0.0494
Total |  1076.77387       100  10.7677387   Root MSE        =    3.1993

------------------------------------------------------------------------------
y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
x |  -.1257176   .0504933    -2.49   0.014    -.2259073   -.0255279
------------------------------------------------------------------------------
``````

$x$ 的系数是负的且是显著的。我使用带 `resid` 选项的 `predict` 命令来获得残差，用 `dfuller` 命令来做 ADF 检验。我使用 `noconstant` 选项使回归中不包含残差项，用 `lags(2)` 选项来对序列相关做出调整。`dfuller` 命令中的 `noconstant` 选项意味着拟合随机游走模型。

``````. predict spurious_resd, resid

. dfuller spurious_resd, nocons lags(2)

Augmented Dickey-Fuller test for unit root         Number of obs   =        97

---------- Interpolated Dickey-Fuller ---------
Test         1% Critical       5% Critical      10% Critical
Statistic           Value             Value             Value
------------------------------------------------------------------------------
Z(t)             -1.599            -2.601            -1.950            -1.610
``````

``````. use coint, clear

. reg y x, nocons

Source |       SS           df       MS      Number of obs   =       100
-------------+----------------------------------   F(1, 99)        =   3148.28
Model |  4411.48377         1  4411.48377   Prob > F        =    0.0000
Residual |   138.72255        99  1.40123788   R-squared       =    0.9695
-------------+----------------------------------   Adj R-squared   =    0.9692
Total |  4550.20632       100  45.5020632   Root MSE        =    1.1837

------------------------------------------------------------------------------
y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
x |   .7335899   .0130743    56.11   0.000     .7076477    .7595321
------------------------------------------------------------------------------

. predict coint_resd, resid

. dfuller coint_resd, nocons lags(2)

Augmented Dickey-Fuller test for unit root         Number of obs   =        97

---------- Interpolated Dickey-Fuller ---------
Test         1% Critical       5% Critical      10% Critical
Statistic           Value             Value             Value
------------------------------------------------------------------------------
Z(t)             -5.955            -2.601            -1.950            -1.610
``````

参考文献

1. Engle, R. F., and C. W. J. Granger. 1987. Co-integration and error correction: Representation, estimation, and testing. Econometrica 55: 251–276.
2. Hamilton, J. D. 1994. Time Series Analysis. Princeton: Princeton University Press.
3. Hansen, B. E. 1992. Effcient estimation and testing of cointegrating vectors in the presence of deterministic trends. Journal of Econometrics 53: 87–121.
4. Phillips, P. C. B. 1986. Understanding spurious regressions in econometrics. Journal of Econometrics 33: 311–340.
5. Phillips, P. C. B., and S. Ouliaris. 1990. Asymptotic properties of residual based tests for cointegration. Econometrica 58: 165–193.

4. 附录

伪回归代码

``````cscript
set seed 2016

local MC = 1000

quietly postfile spurious beta_t100 using t100, replace

forvalues i=1/`MC' {
quietly {
drop _all

set obs 100
gen time = _n
tsset time

gen nu_y = rnormal(0,0.7)
gen nu_x = rnormal(0,1.5)

gen err_y = nu_y in 1
gen err_x = nu_x in 1
replace err_y = l.err_y + nu_y in 2/l
replace err_x = l.err_x + nu_x in 2/l

gen y = err_y in 1
gen x = err_x
replace y = 0.7*x + err_y in 2/l
if (`i'==1) save spurious, replace
qui reg y x, nocons
}
post spurious (_b[x])
}
postclose spurious
``````

协整代码

``````cscript
set seed 2016

local MC = 1000

quietly postfile coint beta_t100 using t100, replace

forvalues i=1/`MC' {
quietly {
drop _all

set obs 100
gen time = _n
tsset time

matrix V = (1,0.7\0.7,1.5)
drawnorm nu_y nu_x, cov(V)

gen err_y = nu_y in 1
gen err_x = nu_x in 1
replace err_y = 0.3*l.nu_y + 0.4*l.nu_x ///
+ nu_y in 2/l
replace err_x = 0.7*l.nu_y + 0.1*l.nu_x ///
+ nu_x in 2/l

gen x = err_x in 1
replace x = l.x + err_x in 2/l
gen y = 0.7*x + err_y
if (`i'==1) save coint, replace
qui reg y x, nocons
}
post coint (_b[x])
}
postclose coint
``````

画图代码

``````/*Spurious regression*/
use t100, clear
quietly merge 1:1 _n using t200
drop _merge
quietly merge 1:1 _n using t1000
drop _merge
kdensity beta_t100, n(1000) generate(x_100 f_100) ///
kernel(gaussian) nograph
label variable f_100 "T=100"
kdensity beta_t200, n(1000) generate(x_200 f_200) ///
kernel(gaussian) nograph
label variable f_200 "T=200"
kdensity beta_t1000, n(1000) generate(x_1000 f_1000) ///
kernel(gaussian) nograph
label variable f_1000 "T=1000"
graph twoway (line f_100 x_100) (line f_200 x_200) ///
(line f_1000 x_1000), legend(rows(1))      ///
subtitle("Spurious regression")            ///
saving(spurious, replace) xmlabel(0.7)     ///
xline(0.7, lcolor(black)) nodraw

/*Cointegration*/
use t100, clear
quietly merge 1:1 _n using t200
drop _merge
quietly merge 1:1 _n using t1000
drop _merge
kdensity beta_t100, n(1000) generate(x_100 f_100) ///
kernel(gaussian) nograph
label variable f_100 "T=100"
kdensity beta_t200, n(1000) generate(x_200 f_200) ///
kernel(gaussian) nograph
label variable f_200 "T=200"
kdensity beta_t1000, n(1000) generate(x_1000 f_1000) ///
kernel(gaussian) nograph
label variable f_1000 "T=1000"
graph twoway (line f_100 x_100) (line f_200 x_200) ///
(line f_1000 x_1000), legend(rows(1))      ///
subtitle("Cointegration")                  ///
saving(cointegration, replace)             ///
xline(0.7, lcolor(black)) nodraw

graph combine spurious.gph cointegration.gph,      ///
title("Empirical densities of {&beta}")
``````

相关课程

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

参考资料

[1]

Posts by Ashish Rajbhandari, Senior Econometrician: https://blog.stata.com/author/arajbhandari/