Chapter 11. Further Issues in Using OLS with Time Series Data#

Home | Stata | R

import statsmodels.formula.api as smf
from wooldridge import *

Example 11.4. Efficient Markets Hypothesis#

df = dataWoo("nyse")
print(smf.ols('df[("return")] ~ return_1 + 1', data=df).fit().summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:         df[("return")]   R-squared:                       0.003
Model:                            OLS   Adj. R-squared:                  0.002
Method:                 Least Squares   F-statistic:                     2.399
Date:                Mon, 11 Dec 2023   Prob (F-statistic):              0.122
Time:                        18:37:21   Log-Likelihood:                -1491.2
No. Observations:                 689   AIC:                             2986.
Df Residuals:                     687   BIC:                             2996.
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
Intercept      0.1796      0.081      2.225      0.026       0.021       0.338
return_1       0.0589      0.038      1.549      0.122      -0.016       0.134
==============================================================================
Omnibus:                      114.206   Durbin-Watson:                   1.997
Prob(Omnibus):                  0.000   Jarque-Bera (JB):              646.991
Skew:                          -0.598   Prob(JB):                    3.22e-141
Kurtosis:                       7.594   Cond. No.                         2.14
==============================================================================

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

Equation [11.18]#

df =dataWoo("nyse")
mrk_lag2 = smf.ols('df[("return")] ~ return_1 + df[("return")].shift(2)', data=df).fit()
print(mrk_lag2.summary())     
                            OLS Regression Results                            
==============================================================================
Dep. Variable:         df[("return")]   R-squared:                       0.005
Model:                            OLS   Adj. R-squared:                  0.002
Method:                 Least Squares   F-statistic:                     1.659
Date:                Mon, 11 Dec 2023   Prob (F-statistic):              0.191
Time:                        18:37:21   Log-Likelihood:                -1489.0
No. Observations:                 688   AIC:                             2984.
Df Residuals:                     685   BIC:                             2998.
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
===========================================================================================
                              coef    std err          t      P>|t|      [0.025      0.975]
-------------------------------------------------------------------------------------------
Intercept                   0.1857      0.081      2.289      0.022       0.026       0.345
return_1                    0.0603      0.038      1.580      0.115      -0.015       0.135
df[("return")].shift(2)    -0.0381      0.038     -0.998      0.319      -0.113       0.037
==============================================================================
Omnibus:                      117.320   Durbin-Watson:                   1.998
Prob(Omnibus):                  0.000   Jarque-Bera (JB):              652.237
Skew:                          -0.627   Prob(JB):                    2.34e-142
Kurtosis:                       7.602   Cond. No.                         2.22
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
hypotheses = '(return_1 = df[("return")].shift(2) = 0)'
f_test = mrk_lag2.f_test(hypotheses)
print(f_test)
<F test: F=1.6585712253772926, p=0.19117456962590035, df_denom=685, df_num=2>

Example 11.5. Expectations Augmented Phillips Curve#

df = dataWoo("phillips")
print(smf.ols('cinf ~ unem + 1', data=df[(df['year']<1997)]).fit().summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                   cinf   R-squared:                       0.108
Model:                            OLS   Adj. R-squared:                  0.088
Method:                 Least Squares   F-statistic:                     5.558
Date:                Mon, 11 Dec 2023   Prob (F-statistic):             0.0227
Time:                        18:37:21   Log-Likelihood:                -110.12
No. Observations:                  48   AIC:                             224.2
Df Residuals:                      46   BIC:                             228.0
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
Intercept      3.0306      1.377      2.201      0.033       0.259       5.802
unem          -0.5426      0.230     -2.357      0.023      -1.006      -0.079
==============================================================================
Omnibus:                       22.805   Durbin-Watson:                   1.770
Prob(Omnibus):                  0.000   Jarque-Bera (JB):               52.071
Skew:                          -1.239   Prob(JB):                     4.93e-12
Kurtosis:                       7.460   Cond. No.                         23.9
==============================================================================

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

Example 11.6. Fertility Equation#

df = dataWoo("fertil3")
fert_lag2 = smf.ols('cgfr ~ cpe + df[("cpe")].shift(1) + df[("cpe")].shift(2)', data = df).fit()
print(fert_lag2.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                   cgfr   R-squared:                       0.232
Model:                            OLS   Adj. R-squared:                  0.197
Method:                 Least Squares   F-statistic:                     6.563
Date:                Mon, 11 Dec 2023   Prob (F-statistic):           0.000605
Time:                        18:37:21   Log-Likelihood:                -189.03
No. Observations:                  69   AIC:                             386.1
Df Residuals:                      65   BIC:                             395.0
Df Model:                           3                                         
Covariance Type:            nonrobust                                         
========================================================================================
                           coef    std err          t      P>|t|      [0.025      0.975]
----------------------------------------------------------------------------------------
Intercept               -0.9637      0.468     -2.060      0.043      -1.898      -0.029
cpe                     -0.0362      0.027     -1.352      0.181      -0.090       0.017
df[("cpe")].shift(1)    -0.0140      0.028     -0.507      0.614      -0.069       0.041
df[("cpe")].shift(2)     0.1100      0.027      4.092      0.000       0.056       0.164
==============================================================================
Omnibus:                        4.167   Durbin-Watson:                   1.414
Prob(Omnibus):                  0.124   Jarque-Bera (JB):                3.673
Skew:                           0.323   Prob(JB):                        0.159
Kurtosis:                       3.928   Cond. No.                         20.7
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
hypotheses = '(cpe = df[("cpe")].shift(1) = 0)'
f_test = fert_lag2.f_test(hypotheses)
print(f_test)
<F test: F=1.2894143663583932, p=0.2823824025023747, df_denom=65, df_num=2>

Example 11.7. Wages and Productivity#

print(smf.ols('lhrwage ~ loutphr + t', data=dataWoo("earns")).fit().summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                lhrwage   R-squared:                       0.971
Model:                            OLS   Adj. R-squared:                  0.970
Method:                 Least Squares   F-statistic:                     641.2
Date:                Mon, 11 Dec 2023   Prob (F-statistic):           5.27e-30
Time:                        18:37:21   Log-Likelihood:                 89.196
No. Observations:                  41   AIC:                            -172.4
Df Residuals:                      38   BIC:                            -167.3
Df Model:                           2                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
Intercept     -5.3285      0.374    -14.230      0.000      -6.086      -4.570
loutphr        1.6396      0.093     17.565      0.000       1.451       1.829
t             -0.0182      0.002    -10.428      0.000      -0.022      -0.015
==============================================================================
Omnibus:                        1.119   Durbin-Watson:                   0.567
Prob(Omnibus):                  0.572   Jarque-Bera (JB):                0.913
Skew:                          -0.055   Prob(JB):                        0.633
Kurtosis:                       2.277   Cond. No.                     2.12e+03
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 2.12e+03. This might indicate that there are
strong multicollinearity or other numerical problems.
print(smf.ols('ghrwage ~ goutphr', data=dataWoo("earns")).fit().summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                ghrwage   R-squared:                       0.364
Model:                            OLS   Adj. R-squared:                  0.348
Method:                 Least Squares   F-statistic:                     21.77
Date:                Mon, 11 Dec 2023   Prob (F-statistic):           3.75e-05
Time:                        18:37:21   Log-Likelihood:                 107.37
No. Observations:                  40   AIC:                            -210.7
Df Residuals:                      38   BIC:                            -207.4
Df Model:                           1                                         
Covariance Type:            nonrobust                                         
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
Intercept     -0.0037      0.004     -0.868      0.391      -0.012       0.005
goutphr        0.8093      0.173      4.666      0.000       0.458       1.160
==============================================================================
Omnibus:                        2.405   Durbin-Watson:                   1.526
Prob(Omnibus):                  0.300   Jarque-Bera (JB):                1.340
Skew:                           0.325   Prob(JB):                        0.512
Kurtosis:                       3.618   Cond. No.                         64.7
==============================================================================

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

Example 11.8. Fertility Equation#

df = dataWoo("fertil3")
fert_lags = smf.ols('cgfr ~ df[("cgfr")].shift(1) + cpe + df[("cpe")].shift(1) + df[("cpe")].shift(2)', 
                    data =df).fit()
print(fert_lags.summary())
                            OLS Regression Results                            
==============================================================================
Dep. Variable:                   cgfr   R-squared:                       0.318
Model:                            OLS   Adj. R-squared:                  0.275
Method:                 Least Squares   F-statistic:                     7.464
Date:                Mon, 11 Dec 2023   Prob (F-statistic):           5.34e-05
Time:                        18:37:21   Log-Likelihood:                -184.95
No. Observations:                  69   AIC:                             379.9
Df Residuals:                      64   BIC:                             391.1
Df Model:                           4                                         
Covariance Type:            nonrobust                                         
=========================================================================================
                            coef    std err          t      P>|t|      [0.025      0.975]
-----------------------------------------------------------------------------------------
Intercept                -0.7022      0.454     -1.547      0.127      -1.609       0.204
df[("cgfr")].shift(1)     0.3002      0.106      2.835      0.006       0.089       0.512
cpe                      -0.0455      0.026     -1.773      0.081      -0.097       0.006
df[("cpe")].shift(1)      0.0021      0.027      0.077      0.939      -0.051       0.056
df[("cpe")].shift(2)      0.1051      0.026      4.108      0.000       0.054       0.156
==============================================================================
Omnibus:                        1.628   Durbin-Watson:                   1.941
Prob(Omnibus):                  0.443   Jarque-Bera (JB):                0.979
Skew:                           0.051   Prob(JB):                        0.613
Kurtosis:                       3.575   Cond. No.                         21.2
==============================================================================

Notes:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
hypotheses = '(cpe = df[("cpe")].shift(1) = 0)'
f_test = fert_lags.f_test(hypotheses)
print(f_test)
<F test: F=1.6557713220149344, p=0.19901864509281858, df_denom=64, df_num=2>