同時方程式体系

『Rによる計量経済学』第10章「同時方程式体系」をPythonで実行する。
テキスト付属データセット(「k1001.csv」等)については出版社サイトよりダウンロードしてください。
また、以下の説明は本書の一部を要約したものですので、より詳しい説明は本書を参照してください。

例題10.1

次のような供給関数と需要関数を推定する。
$Q_{t} = \alpha_{0} + \alpha_{1} P_{t} + \alpha_{2} E_{t} + u_{t}$
$Q_{t} = \beta_{0} + \beta_{1} P_{t} + \beta_{2} A_{t} + v_{t}$
ただし、$Q_{t}$ は数量、$P_{t}$ は価格、$E_{t}$ は供給関数シフト要因、$A_{t}$ は需要関数シフト要因とする。


In [1]:
%matplotlib inline

In [2]:
# -*- coding:utf-8 -*-
from __future__ import print_function
import numpy as np
import pandas as pd
import statsmodels.api as sm
from statsmodels.sandbox.regression.gmm import IV2SLS
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')

In [3]:
# データ読み込み
data = pd.read_csv('example/k1001.csv')

In [4]:
# 式1説明変数設定
X1 = data[['P', 'E']].as_matrix().reshape(-1, 2)
X1 = sm.add_constant(X1)
# 式2説明変数設定
X2 = data[['P', 'A']].as_matrix().reshape(-1, 2)
X2 = sm.add_constant(X2)

In [5]:
# 被説明変数設定
Y = data[['Q']].as_matrix().reshape(-1)

In [6]:
# OLSの実行(Ordinary Least Squares: 最小二乗法)
model1 = sm.OLS(Y, X1)
model2 = sm.OLS(Y, X2)
result1 = model1.fit()
result2 = model2.fit()

In [7]:
print(result1.summary())


                            OLS Regression Results                            
==============================================================================
Dep. Variable:                      y   R-squared:                       0.529
Model:                            OLS   Adj. R-squared:                  0.474
Method:                 Least Squares   F-statistic:                     9.548
Date:                Sun, 19 Jul 2015   Prob (F-statistic):            0.00166
Time:                        04:06:29   Log-Likelihood:                -22.259
No. Observations:                  20   AIC:                             50.52
Df Residuals:                      17   BIC:                             53.51
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
const          4.8581      0.695      6.988      0.000         3.391     6.325
x1             1.5094      0.379      3.983      0.001         0.710     2.309
x2            -1.5202      0.353     -4.308      0.000        -2.265    -0.776
==============================================================================
Omnibus:                        1.092   Durbin-Watson:                   1.191
Prob(Omnibus):                  0.579   Jarque-Bera (JB):                0.757
Skew:                           0.458   Prob(JB):                        0.685
Kurtosis:                       2.740   Cond. No.                         31.6
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

In [8]:
print(result2.summary())


                            OLS Regression Results                            
==============================================================================
Dep. Variable:                      y   R-squared:                       0.627
Model:                            OLS   Adj. R-squared:                  0.583
Method:                 Least Squares   F-statistic:                     14.30
Date:                Sun, 19 Jul 2015   Prob (F-statistic):           0.000227
Time:                        04:06:29   Log-Likelihood:                -19.920
No. Observations:                  20   AIC:                             45.84
Df Residuals:                      17   BIC:                             48.83
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
const         16.6747      1.905      8.752      0.000        12.655    20.694
x1            -0.9088      0.180     -5.047      0.000        -1.289    -0.529
x2            -1.0369      0.196     -5.285      0.000        -1.451    -0.623
==============================================================================
Omnibus:                        1.032   Durbin-Watson:                   0.660
Prob(Omnibus):                  0.597   Jarque-Bera (JB):                0.132
Skew:                           0.086   Prob(JB):                        0.936
Kurtosis:                       3.358   Cond. No.                         90.0
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.

この結果から古典的最小二乗法による推定式をまとめると、
[供給関数]
$\hat Q_{i} = 4.8581 + 1.5094 P_{i} - 1.5202 E_{i} $
[需要関数]
$\hat Q_{i} = 16.6747 - 0.9088 P_{i} - 1.0369 A_{i}$
となる。

しかし、説明変数Pと誤差の間に関係があるため、同時方程式バイアスが生じてしまいます。

そこで、以下では同時方程式体系の推定法として代表的な二段階最小二乗法を用いて推定し直します。


In [9]:
# 外生変数設定
inst = data[[ 'A', 'E']].as_matrix()
inst = sm.add_constant(inst)

In [10]:
# 2SLSの実行(Two Stage Least Squares: 二段階最小二乗法)
model1 = IV2SLS(Y, X1, inst)
model2 = IV2SLS(Y, X2, inst)
result1 = model1.fit()
result2 = model2.fit()

In [11]:
print(result1.summary())


                          IV2SLS Regression Results                           
==============================================================================
Dep. Variable:                      y   R-squared:                       0.434
Model:                         IV2SLS   Adj. R-squared:                  0.367
Method:                     Two Stage   F-statistic:                     10.66
                        Least Squares   Prob (F-statistic):            0.00100
Date:                Sun, 19 Jul 2015                                         
Time:                        04:06:29                                         
No. Observations:                  20                                         
Df Residuals:                      17                                         
Df Model:                           2                                         
==============================================================================
                 coef    std err          t      P>|t|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
const          3.7867      0.889      4.259      0.001         1.911     5.663
x1             2.2119      0.513      4.315      0.000         1.130     3.293
x2            -2.1531      0.472     -4.561      0.000        -3.149    -1.157
==============================================================================
Omnibus:                        3.627   Durbin-Watson:                   1.436
Prob(Omnibus):                  0.163   Jarque-Bera (JB):                2.600
Skew:                           0.881   Prob(JB):                        0.273
Kurtosis:                       2.872   Cond. No.                         31.6
==============================================================================

In [12]:
print(result2.summary())


                          IV2SLS Regression Results                           
==============================================================================
Dep. Variable:                      y   R-squared:                       0.618
Model:                         IV2SLS   Adj. R-squared:                  0.573
Method:                     Two Stage   F-statistic:                     15.80
                        Least Squares   Prob (F-statistic):           0.000133
Date:                Sun, 19 Jul 2015                                         
Time:                        04:06:29                                         
No. Observations:                  20                                         
Df Residuals:                      17                                         
Df Model:                           2                                         
==============================================================================
                 coef    std err          t      P>|t|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
const         17.8558      2.023      8.828      0.000        13.589    22.123
x1            -1.0249      0.192     -5.342      0.000        -1.430    -0.620
x2            -1.1484      0.207     -5.554      0.000        -1.585    -0.712
==============================================================================
Omnibus:                        0.871   Durbin-Watson:                   0.673
Prob(Omnibus):                  0.647   Jarque-Bera (JB):                0.081
Skew:                          -0.067   Prob(JB):                        0.960
Kurtosis:                       3.282   Cond. No.                         90.0
==============================================================================

この結果から二段階最小二乗法による推定式をまとめると、
[供給関数]
$\hat Q_{i} = 3.7867 + 2.2119 P_{i} - 2.1531 E_{i} $
[需要関数]
$\hat Q_{i} = 17.8558 - 1.0249 P_{i} - 1.1484 A_{i}$
となる。