Differences in Differences

The most straightforward method of measuring the price effects of a particular treatment is to compare the price before the treatment with the price after the treatment. Ideally, such a comparison must control for those changes in demand and cost that would also affect price. One basic approach to doing this identifies the cost and demand factors that affect price and then estimates the relationship between price and these factors plus a dummy variable or set of dummy variables accounting for the treatment.

This approach, however, requires that the researcher know what cost and demand factors affect price, and obtain detailed time-series data measuring these factors. These requirements make this approach in-feasible in many cases.

Difference-in-Differences (DID) estimation, compares price changes in a market where the treatment occurred (treatment market) with price changes in a market subject to similar cost and demand shocks where no treatment occurred (control market). In so doing, the DID approach makes the implicit assumption that price changes in the control market fully control for cost and demand shocks in the treatment market when the two markets experience similar cost and demand shocks.

Deepwater Horizon and Its Effect on the Economy

The Deepwater Horizon was an offshore oil drilling rug operated by Transocean and leased by British Petroleum(BP). On April 20, 2010, an explosion on the rig caused by a blowout led to a massive oil spill in the Gulf of Mexico, killing 11 workers and releasing an estimated 4.9 million barrels of oil into the ocean over 87 days. The disaster had devastating ecological consequences, harming marine life, damaging local ecosystems, and impacting the local fishing industry. It also raised concerns about the safety practices of oil companies and prompted significant regulatory changes in offshore drilling operations. This analysis will examine how the event affected the stock prices of BP and Exxon Mobil, with pre and post-periods identified.

The data ‘Deepwaterhorizon.csv’ contains data on the daily stock price of British Petroleum(BP) and Exxon Mobil(XOM) from 2005 to 2015. Our identifier for the event is labeled in the column Spill, where 0 represents the pre-period and 1 represents the post-period.

mydata <- read.csv("Deepwaterhorizon.csv", header = TRUE)
view(mydata)

mydata$Spill = ifelse(mydata$Date >= as.Date("2010-04-20"), 1, 0)
table(mydata$Spill)
## 
##    0    1 
## 1332 1224
mydata %>% 
  group_by(Spill) %>%
    dplyr::summarise(mean(BP), mean(XOM))
## # A tibble: 2 × 3
##   Spill `mean(BP)` `mean(XOM)`
##   <dbl>      <dbl>       <dbl>
## 1     0       61.8        71.8
## 2     1       43.3        85.0

As displayed in the table, the average stock price of BP decreased by 18.5 points while the average stock price of XOM increased by 13.2 points. This divergence suggests that the markets penalized BP heavily for the disaster, while Exxon was rewarded for safety and stability.

plot(as.Date(mydata$Date), mydata$BP, type = "l", col = "blue", ylim = range(c(mydata$BP, mydata$XOM)), 
     xlab = "Date", ylab = "Stock Price", main = "BP and XOM Stock Prices")
lines(as.Date(mydata$Date), mydata$XOM, col = "black")
abline(v = as.Date("2010-04-20"), lwd = 2, col = "red")
legend("bottomleft", legend = c("BP", "XOM"), col = c("blue", "black"), lty = 1)

Through plotting the time-series data, we can better view the overall results of the Deepwater Horizon event. While the two stocks resembled each other in moves from late 2007 to 2010, the event caused very different results in the future direction of the stocks. The vertical line represents the date of the event. After the spill, BP’s stock sharply declined, while Exxon’s had a smaller drop and significant rally after.

Applying DID estimation

To start DID estimation, our data needs to transform from two dependent variables to one. We can do this by using tidyr’s pivot_longer function. Once we pivot the table, we can include a new column, Treatment, that identifies the treated group, BP. We also create a new column, DIF, which will serve as the key variable in DID-analysis.

mydata2 = mydata %>% 
  pivot_longer(cols = c(XOM, BP), values_to = "Outcome")
     
mydata2$Treatment = ifelse(mydata2$name == "BP", 1, 0)
     
mydata2$DIF = mydata2$Treatment*mydata2$Spill
head(mydata2)
## # A tibble: 6 × 6
##   Date       Spill name  Outcome Treatment   DIF
##   <chr>      <dbl> <chr>   <dbl>     <dbl> <dbl>
## 1 2005-01-03     0 XOM      50.1         0     0
## 2 2005-01-03     0 BP       57.1         1     0
## 3 2005-01-04     0 XOM      49.8         0     0
## 4 2005-01-04     0 BP       56.6         1     0
## 5 2005-01-05     0 XOM      49.5         0     0
## 6 2005-01-05     0 BP       56.7         1     0
mydata2 %>% group_by(Spill, Treatment) %>%
       dplyr::summarise(means = mean(Outcome))
## # A tibble: 4 × 3
## # Groups:   Spill [2]
##   Spill Treatment means
##   <dbl>     <dbl> <dbl>
## 1     0         0  71.8
## 2     0         1  61.8
## 3     1         0  85.0
## 4     1         1  43.3

By grouping the data by event-occurence and if it belongs to the Treatment group, we find the means of each subset of data. DID is calculated by the following formula:

(BP after - BP before) - (XOM after - XOM before)

The difference-in-difference estimate of our data is -31.7, which estimates that the Deepwater Horizon spill caused the stock price of BP to drop by 31.7 points more than that of XOM.

Regression Analysis

Regression Analysis is performed using the lm() function in R. Our regression consists of predicting Outcome on the variables Treatment, Spill, and DIF. Treatment represents the stock ticker, with 1 for BP and 0 for XOM. Spill shows 0 for the pre-period and 1 for the post-period. Our interaction term DIF captures the causal effect of the spill.

reg_did = lm(Outcome ~ Treatment + Spill + DIF, data = mydata2 )
summary(reg_did)
## 
## Call:
## lm(formula = Outcome ~ Treatment + Spill + DIF, data = mydata2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -28.452  -4.774   0.568   5.760  23.240 
## 
## Coefficients:
##             Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)   71.810      0.256   280.2 <0.0000000000000002 ***
## Treatment     -9.993      0.362   -27.6 <0.0000000000000002 ***
## Spill         13.212      0.370    35.7 <0.0000000000000002 ***
## DIF          -31.737      0.524   -60.6 <0.0000000000000002 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 9.35 on 5108 degrees of freedom
## Multiple R-squared:  0.719,  Adjusted R-squared:  0.718 
## F-statistic: 4.35e+03 on 3 and 5108 DF,  p-value: <0.0000000000000002

The regression model has a multiple R-squared of 0.719, which shows the model explains approximately 71.9% of the variance in the stock prices. The Intercept, 71.810, represents the average stock price of XOM before the Deepwater Horizon spill. The coefficient on Treatment is -9.993, indicating that before the spill BP’s average stock price was 9.993 points lower than that of XOM. The p-value of Treatment is statistically significant, as indicated by the triple asterisk and p-value being less than 0.001. The Spill coefficient is 13.212, which means the average stock price of companies increased by 13.212 points after the spill. However, this could represent general market conditions. The interaction term DIF has a coefficient of -31.74, which is matches our estimation. The overall F-statistic (F=4350, p < 0.001) confirms that the model is highly significant and that the included variables explain a substantial portion of the variation of stock prices. The variables are displayed neatly in the following regression table:

## 
## =============================================
##                       Dependent variable:    
##                   ---------------------------
##                             Outcome          
##                                              
## ---------------------------------------------
## Intercept (B0)             71.80***          
##                             (0.26)           
##                                              
## Treatment (B1)             -9.99***          
##                             (0.36)           
##                                              
## Post-spill (B2)            13.20***          
##                             (0.37)           
##                                              
## Diff in Diff (B3)          -31.70***         
##                             (0.52)           
##                                              
## =============================================
## =============================================
## Note:             *p<0.1; **p<0.05; ***p<0.01

Conclusion and Use Cases in Other Events

This analysis aimed to assess the financial impact of the Deepwater Horizon spill on BP by comparing stock performance to Exxon Mobil. The results show that BP experienced a significant post-spill decline in the average stock price, with a DID estimate of approximately -31.7 points. While the model explains over 70% of the variation in stock price, the analysis is limited by comparing only two stocks and a lack of a control for external economic factors. However, the analysis highlights the severe consequences of environmental disasters on firm value and underscores the utility of DID framework in isolating effects.

The broader relevance of this analysis extends to other real world policy shocks, such as the tariffs enacted by the Trump administration. The tariffs on commodities such as steel, aluminum, and lumber serve as events that are perfect for DID analysis. While the framework is applied to disasters, policy analysis is also a perfect topic for DID framework.