Skip to content

第七章 本章介绍(时间序列分析与事件研究)

从时间维度理解社会经济现象:趋势、周期与因果

难度重要性


本章目标

完成本章后,你将能够:

  • 理解时间序列数据的基本特征(趋势、季节性、周期)
  • 掌握时间序列分解的方法和应用
  • 使用 ARIMA 模型进行预测
  • 进行平稳性检验(ADF、KPSS)
  • 实施事件研究方法(Event Study)
  • 评估政策效应和冲击影响
  • 使用 Python 工具包(statsmodels, pandas)

为什么时间序列分析如此重要?

社会科学中的时间维度

时间序列数据无处不在

  • 宏观经济学:GDP、通货膨胀、失业率、利率
  • 金融经济学:股票价格、汇率、期货价格
  • 劳动经济学:就业人数、工资水平、劳动参与率
  • 公共政策:政策前后对比、政策效应评估
  • 社会学:犯罪率、人口出生率、教育入学率

时间序列 vs 横截面数据

特征横截面数据时间序列数据
观测对象多个个体,单一时点单个/多个个体,多个时点
独立性假设通常满足(i.i.d.)违反(序列相关)
典型问题个体差异、遗漏变量趋势、季节性、自相关
分析方法OLS、横截面回归ARIMA、VAR、协整
因果推断RCT、IV、RDDDID、事件研究、断点

经典案例:Box & Jenkins (1970)

航空乘客数据:1949-1960年的月度国际航空乘客数量

python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from statsmodels.datasets import co2

# 加载经典数据集
data = co2.load_pandas().data

# 可视化
fig, axes = plt.subplots(2, 1, figsize=(14, 8))

# 原始序列
axes[0].plot(data.index, data.values, linewidth=1.5)
axes[0].set_title('大气 CO₂ 浓度(1958-2001)', fontsize=14, fontweight='bold')
axes[0].set_ylabel('CO₂ (ppm)')
axes[0].grid(True, alpha=0.3)

# 年度平均
yearly = data.resample('Y').mean()
axes[1].plot(yearly.index, yearly.values, linewidth=2, marker='o')
axes[1].set_title('年度平均 CO₂ 浓度', fontsize=14, fontweight='bold')
axes[1].set_ylabel('CO₂ (ppm)')
axes[1].set_xlabel('年份')
axes[1].grid(True, alpha=0.3)

plt.tight_layout()
plt.show()

观察到的特征

  1. 趋势(Trend):长期上升趋势
  2. 季节性(Seasonality):每年的周期性波动
  3. 随机波动(Random):不可预测的短期波动

时间序列的核心概念

1. 平稳性(Stationarity)

定义:时间序列的统计性质不随时间变化

严平稳(Strict Stationarity)

弱平稳(Weak Stationarity / Covariance Stationarity)

  1. (均值不变)
  2. (方差不变)
  3. (自协方差只依赖于滞后阶数)

为什么平稳性重要?

  • 非平稳序列可能导致伪回归(Spurious Regression)
  • 许多时间序列模型(如ARIMA)要求序列平稳
  • 预测依赖于统计性质的稳定性

图示

python
np.random.seed(42)
n = 200

# 平稳序列:白噪声
stationary = np.random.normal(0, 1, n)

# 非平稳序列:随机游走
random_walk = np.cumsum(np.random.normal(0, 1, n))

# 非平稳序列:确定性趋势
trend = np.arange(n) * 0.1 + np.random.normal(0, 1, n)

fig, axes = plt.subplots(3, 1, figsize=(14, 10))

axes[0].plot(stationary)
axes[0].set_title('平稳序列:白噪声', fontsize=14, fontweight='bold')
axes[0].axhline(y=0, color='r', linestyle='--', alpha=0.5)
axes[0].set_ylabel('值')
axes[0].grid(True, alpha=0.3)

axes[1].plot(random_walk, color='orange')
axes[1].set_title('非平稳序列:随机游走(单位根)', fontsize=14, fontweight='bold')
axes[1].set_ylabel('值')
axes[1].grid(True, alpha=0.3)

axes[2].plot(trend, color='green')
axes[2].set_title('非平稳序列:确定性趋势', fontsize=14, fontweight='bold')
axes[2].set_xlabel('时间')
axes[2].set_ylabel('值')
axes[2].grid(True, alpha=0.3)

plt.tight_layout()
plt.show()

2. 自相关(Autocorrelation)

定义:时间序列与其滞后值之间的相关性

自相关函数(ACF)

偏自相关函数(PACF)

  • 控制中间滞后项后, 的相关性
  • 用于识别 AR 阶数

示例

python
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

# 生成 AR(1) 过程
np.random.seed(42)
phi = 0.8
ar1 = [0]
for i in range(1, 200):
    ar1.append(phi * ar1[-1] + np.random.normal(0, 1))

fig, axes = plt.subplots(1, 3, figsize=(16, 5))

# 时间序列图
axes[0].plot(ar1)
axes[0].set_title('AR(1) 序列: $y_t = 0.8 y_{t-1} + \epsilon_t$', fontsize=14, fontweight='bold')
axes[0].grid(True, alpha=0.3)

# ACF
plot_acf(ar1, lags=20, ax=axes[1], alpha=0.05)
axes[1].set_title('自相关函数(ACF)', fontsize=14, fontweight='bold')

# PACF
plot_pacf(ar1, lags=20, ax=axes[2], alpha=0.05)
axes[2].set_title('偏自相关函数(PACF)', fontsize=14, fontweight='bold')

plt.tight_layout()
plt.show()

解读

  • ACF:指数衰减(AR过程特征)
  • PACF:滞后1阶显著,其余不显著(识别为AR(1))

3. 时间序列模型家族

时间序列模型
├── 经典分解模型
│   ├── 加法模型:Y = T + S + R
│   └── 乘法模型:Y = T × S × R

├── 指数平滑(Exponential Smoothing)
│   ├── 简单指数平滑(SES)
│   ├── Holt 线性趋势
│   └── Holt-Winters 季节性

├── ARIMA 家族
│   ├── AR(自回归)
│   ├── MA(移动平均)
│   ├── ARMA
│   ├── ARIMA(带差分)
│   └── SARIMA(季节性)

├── 向量模型
│   ├── VAR(向量自回归)
│   ├── VECM(误差修正模型)
│   └── 结构VAR(SVAR)

└── 高级模型
    ├── GARCH(波动率模型)
    ├── 状态空间模型
    └── Prophet(Facebook)

事件研究方法(Event Study)

定义与应用

事件研究:评估特定事件对某个变量的影响

经典应用场景

  1. 金融市场

    • 公司并购对股价的影响
    • 盈利公告对股票收益的影响
    • 监管政策对市场波动的影响
  2. 公共政策

    • 最低工资法对就业的影响
    • 环境法规对污染的影响
    • 教育改革对考试成绩的影响
  3. 自然灾害

    • 地震对经济活动的影响
    • 疫情对消费行为的影响

事件研究的基本框架

时间轴
├── 估计窗口(Estimation Window)
│   └── 建立"正常"基准

├── 事件窗口(Event Window)
│   ├── 事件前(Pre-event)
│   ├── 事件日(Event Day)
│   └── 事件后(Post-event)

└── 事后窗口(Post-event Window)
    └── 长期效应评估

核心指标

  1. 异常收益(Abnormal Return, AR)
  1. 累积异常收益(Cumulative Abnormal Return, CAR)

图示

python
# 模拟事件研究
np.random.seed(123)
n = 200
event_day = 100

# 正常期收益
normal_returns = np.random.normal(0.001, 0.02, n)

# 在事件日及之后增加异常收益
abnormal_effect = 0.05
normal_returns[event_day:] += abnormal_effect

# 计算累积收益
cumulative_returns = np.cumsum(normal_returns)

fig, axes = plt.subplots(2, 1, figsize=(14, 8))

# 日收益
axes[0].plot(normal_returns, alpha=0.7)
axes[0].axvline(x=event_day, color='r', linestyle='--', linewidth=2, label='事件日')
axes[0].axhline(y=0, color='black', linestyle='-', alpha=0.3)
axes[0].set_title('日收益率', fontsize=14, fontweight='bold')
axes[0].set_ylabel('收益率')
axes[0].legend()
axes[0].grid(True, alpha=0.3)

# 累积异常收益
axes[1].plot(cumulative_returns, linewidth=2)
axes[1].axvline(x=event_day, color='r', linestyle='--', linewidth=2, label='事件日')
axes[1].set_title('累积收益', fontsize=14, fontweight='bold')
axes[1].set_xlabel('时间(天)')
axes[1].set_ylabel('累积收益')
axes[1].legend()
axes[1].grid(True, alpha=0.3)

plt.tight_layout()
plt.show()

本章结构

第 1 节:时间序列基础

  • 时间序列数据的特征
  • Python 中的时间序列处理(pandas)
  • 数据平稳性检验(ADF、KPSS、PP)
  • 差分与变换
  • 案例:中国GDP增长率的平稳性分析

第 2 节:时间序列分解

  • 经典分解方法(加法/乘法模型)
  • STL 分解(Seasonal-Trend Decomposition using Loess)
  • 季节性调整(X-13ARIMA-SEATS)
  • 趋势提取与滤波(HP滤波、BK滤波)
  • 案例:消费者物价指数(CPI)的季节性调整

第 3 节:ARIMA 模型

  • AR、MA、ARMA 模型
  • 单位根与差分
  • ARIMA 模型识别、估计、诊断
  • 模型选择(AIC、BIC)
  • 预测与预测区间
  • SARIMA(季节性ARIMA)
  • 案例:失业率预测

第 4 节:事件研究方法

  • 事件研究的基本框架
  • 正常收益模型(市场模型、均值调整模型)
  • 异常收益的计算
  • 显著性检验(t检验、秩检验)
  • 多事件研究
  • 案例:并购公告对股价的影响

第 5 节:高级专题

  • 向量自回归(VAR)
  • 脉冲响应函数(IRF)
  • 方差分解
  • Granger 因果检验
  • 协整与误差修正模型(VECM)
  • 断点检验(Chow Test、Bai-Perron)
  • 案例:货币政策冲击对通胀的影响

第 6 节:小结和本章复习

  • 知识体系总结
  • 10道高难度编程题
  • 经典文献推荐
  • 学习路径指南

️ Python 工具包

核心库

主要功能安装
pandas时间序列数据处理pip install pandas
statsmodelsARIMA、VAR、协整pip install statsmodels
scipy统计检验pip install scipy
matplotlib可视化pip install matplotlib
seaborn高级可视化pip install seaborn

专业库

主要功能安装
archGARCH 模型pip install arch
pmdarima自动 ARIMApip install pmdarima
prophetFacebook 预测工具pip install prophet
ruptures断点检测pip install ruptures

基础设置

python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
from statsmodels.tsa.stattools import adfuller, kpss, acf, pacf
from statsmodels.tsa.arima.model import ARIMA
from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

# 中文字体设置
plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']  # macOS
# plt.rcParams['font.sans-serif'] = ['SimHei']  # Windows
plt.rcParams['axes.unicode_minus'] = False

# 设置样式
sns.set_style("whitegrid")
plt.rcParams['figure.figsize'] = (12, 6)
plt.rcParams['figure.dpi'] = 100

# pandas 显示设置
pd.set_option('display.max_rows', 100)
pd.set_option('display.max_columns', 20)
pd.set_option('display.width', 1000)

经典文献

必读论文

  1. Box, G. E. P., & Jenkins, G. M. (1970). Time Series Analysis: Forecasting and Control

    • 时间序列分析的奠基之作
    • ARIMA 模型的系统性介绍
  2. Dickey, D. A., & Fuller, W. A. (1979). "Distribution of the Estimators for Autoregressive Time Series with a Unit Root"

    • ADF 单位根检验
    • 平稳性检验的标准方法
  3. Fama, E. F., Fisher, L., Jensen, M. C., & Roll, R. (1969). "The Adjustment of Stock Prices to New Information"

    • 事件研究方法的开山之作
    • 有效市场假说的实证支持
  4. Engle, R. F., & Granger, C. W. J. (1987). "Co-integration and Error Correction"

    • 协整理论(诺贝尔经济学奖)
    • 长期均衡关系

应用文献

  1. Card, D., & Krueger, A. B. (1994). "Minimum Wages and Employment: A Case Study of the Fast-Food Industry in New Jersey and Pennsylvania"

    • 双重差分(DID)方法
    • 自然实验设计
  2. Bertrand, M., Duflo, E., & Mullainathan, S. (2004). "How Much Should We Trust Differences-In-Differences Estimates?"

    • DID 的序列相关问题
    • 聚类标准误

学习路径建议

初学者(1-2周)

目标:掌握时间序列数据的基本处理

学习内容

  • 第1节:平稳性概念、ADF检验
  • 第2节前半部分:时间序列分解
  • 练习:使用真实数据(GDP、CPI)

推荐资源

  • Wooldridge (2020): Chapter 10 "Basic Regression Analysis with Time Series Data"

进阶学习(3-4周)

目标:独立建立 ARIMA 模型

学习内容

  • 第2节后半部分:STL分解
  • 第3节:完整的 ARIMA 建模流程
  • 练习:预测失业率、通胀率

推荐资源

  • Stock & Watson (2020): Chapter 14 "Introduction to Time Series Regression"

高级应用(5-6周)

目标:实施事件研究和 VAR 分析

学习内容

  • 第4节:事件研究方法
  • 第5节:VAR、IRF、Granger因果
  • 练习:政策效应评估

推荐资源

  • Hamilton (1994): Time Series Analysis (经典教材)
  • Lütkepohl (2005): New Introduction to Multiple Time Series Analysis

实践建议

时间序列分析的常见陷阱

  1. 伪回归(Spurious Regression)

    • 问题:两个非平稳序列可能显示高相关,但实际无关
    • 解决:检验平稳性,使用差分或协整
  2. 过度差分(Over-differencing)

    • 问题:不必要的差分会引入MA成分
    • 解决:用 ADF 和 KPSS 联合检验
  3. 忽略结构性断点(Structural Breaks)

    • 问题:政策变化、危机等导致模型参数改变
    • 解决:Chow Test、Bai-Perron 断点检验
  4. 小样本问题

    • 问题:时间序列通常样本量较小
    • 解决:谨慎解释、使用稳健标准误

数据质量检查清单

  • [ ] 检查缺失值(插值 vs 删除)
  • [ ] 识别异常值(极端事件 vs 测量误差)
  • [ ] 确认时间单位和频率(日度、月度、季度)
  • [ ] 检查季节性(节假日效应)
  • [ ] 绘制时间序列图(趋势、断点)
  • [ ] 计算基本统计量(均值、方差、偏度、峰度)

开始学习

准备好探索时间维度的奥秘了吗?

让我们从第1节:时间序列基础开始!

记住

"The best way to predict the future is to understand the past."

"预测未来的最好方法是理解过去。"


时间序列分析:理解过去,预测未来,评估因果!

基于 MIT 许可证发布。内容版权归作者所有。