Testing for a Change in the Slope Coefficient

Table of Contents

1. Overview

We want to test whether there was a change in the relationship between two time series after some event. Assume we can model the relationship between the series with a linear regression, so we want to test whether the slope coefficient changed after some event. Say we are looking at the relationship between two time-series, \(y\) and \(x\).

A standard regression would be:

\[y_t = \alpha + \beta_1 x_t + \epsilon_t\]

In this case \(\beta_1\) measures the relationship between \(x\) and \(y\) over the entire sample. However say we think the relationship changed at time \(t^*\). We then create an indicator variable (\(I\)) which is 0 before \(t^*\) and 1 after.

Our regression would now be:

\[y_t = \alpha + \beta_1 x_t + \beta_2 (x_t I_t) + \epsilon_t\]

where \(x_t I_t\) is the product of \(x_t\) and the indicator variable at time \(t\).

Note the regression prior to the event is:

\[y_t = \alpha + \beta_1 x_t + \epsilon_t\]

because the indicator is 0. After the event, when the indicator is 1, the equation is:

\[y_t = \alpha + (\beta_1 + \beta_2)x_t + \epsilon_t\]

2. 1 vs 2 Month Crude Oil Futures

library(EIAdata)
library(quantmod)
key <- source("~/eia_key")$value
one_month <- getEIA('PET.RCLC1.W', key = key)
two_month <- getEIA('PET.RCLC2.W', key = key)

2.1. No Change in Slope

\[oil\_2_t = \alpha + \beta oil\_1_t + \epsilon\]

oil_data <- merge.xts(Delt(one_month)[-1], Delt(two_month)[-1,], join="inner")
names(oil_data) <- c("one", "two")
oil_data <- oil_data['2015-01-01/']
reg1 <- lm(oil_data$two ~ oil_data$one)
summary(reg1)

Call:
lm(formula = oil_data$two ~ oil_data$one)

Residuals:
     Min       1Q   Median       3Q      Max 
-0.35516 -0.02315  0.00322  0.02237  0.20823 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.0007761  0.0021394   0.363    0.717    
oil_data$one 0.1298306  0.0135754   9.564   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.04503 on 442 degrees of freedom
Multiple R-squared:  0.1715,	Adjusted R-squared:  0.1696 
F-statistic: 91.46 on 1 and 442 DF,  p-value: < 2.2e-16

2.2. Test for a change in Slope Post 1/1/2020

\[oil\_2_t = \alpha + \beta_1 oil\_1_t + \beta_2 * (oil\_1_t * indicator_t) + \epsilon\]

## create an indicator function-----
oil_data$indicator <- ifelse(index(oil_data) < "2020-01-01", 0 , 1)
oil_data
                    one          two indicator
2015-01-02 -0.041621816 -0.040627227         0
2015-01-09 -0.087420442 -0.084881129         0
2015-01-16 -0.034256410 -0.033488939         0
2015-01-23 -0.011894647 -0.011969761         0
2015-01-30 -0.017196905 -0.012327311         0
2015-02-06  0.107830271  0.107811491         0
2015-02-13  0.009674235  0.010878011         0
2015-02-20  0.012710207  0.007686395         0
2015-02-27 -0.043637768 -0.019260107         0
2015-03-06  0.017565112  0.015944002         0
       ...                                    
2023-04-28 -0.036237374 -0.038378993         1
2023-05-05 -0.067732215 -0.066824209         1
2023-05-12  0.012788083  0.013224536         1
2023-05-19 -0.005966422 -0.004582061         1
2023-05-26  0.015494137  0.015204352         1
2023-06-02 -0.039862543 -0.038609508         1
2023-06-09  0.024767359  0.024724882         1
2023-06-16 -0.029896619 -0.029149233         1
2023-06-23  0.014256912  0.015227697         1
2023-06-30 -0.014198495 -0.015282298         1
reg2 <- lm(oil_data$two ~ oil_data$one + I(oil_data$one * oil_data$indicator))
summary(reg2)

Call:
lm(formula = oil_data$two ~ oil_data$one + I(oil_data$one * oil_data$indicator))

Residuals:
      Min        1Q    Median        3Q       Max 
-0.256784 -0.002520 -0.000329  0.004423  0.224879 

Coefficients:
                                       Estimate Std. Error t value Pr(>|t|)    
(Intercept)                           0.0004253  0.0017376   0.245    0.807    
oil_data$one                          0.9598248  0.0559223  17.164   <2e-16 ***
I(oil_data$one * oil_data$indicator) -0.8633876  0.0570306 -15.139   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.03657 on 441 degrees of freedom
Multiple R-squared:  0.4548,	Adjusted R-squared:  0.4523 
F-statistic: 183.9 on 2 and 441 DF,  p-value: < 2.2e-16

Pre covid the slope was 0.96. Post covid the slope was 0.96 + -0.863 = 0.097. The difference in slope coefficients in significant at the 1% level.

Author: Matt Brigida, Ph.D.

Created: 2023-07-13 Thu 10:28

Validate