class: center, middle, inverse, title-slide # Difference in Differences ## EC 320: Introduction to Econometrics ### Emmett Saulnier ### Spring 2022 --- class: inverse, middle # Prologue --- # Housekeeping <br> .hi-pink[Course evaluations] are open - If more than half of the class fills it out, I'll give 2 percentage points of extra credit - I value your feedback! (but please be respectful) -- .hi-pink[Last problem sets] - Analytical problem set 7 due tomorrow (5/27) - Computational problem set 7 due Wednesday (6/1) --- # Cholera in the 1850's .hi-pink[John Snow] used difference-in-differences in 1855 to prove that Cholera was being spread by contaminated water. -- <img src="jon-snow.jpeg" width="80%" style="display: block; margin: auto;" /> (Not this Jon Snow) --- # Cholera in the 1850's .hi-pink[John Snow] used difference-in-differences in 1855 to prove that Cholera was being spread by contaminated water. ### Beliefs at the time It was assumed at the time that Cholera was spread through things like... - Rotting material and bad smells - Low elevation - Bad breeding - Poverty Great examples of .hi-pink[bad econometrics] -- **What might be an "ideal" experiment to test Snow's hypothesis?** --- # Cholera in the 1850's ### A change in water sources Many companies served London's water needs. One of them, the Lambeth Company, changed the location of their water source - **1849**: Thames River *downstream* from London 💩 - **1854**: Thames River *upstream* from London -- Our "treatment" is people having their water pumped from a .hi-blue[clean source]. Lambeth switching their water supply is a natural experiment 1. Calculate change in Cholera rates **before** and **after** the switch for people served by Lambeth 2. Calcuate the change in Cholera rates for some control group over the same time period 3. Take the difference between (1) and (2) .smallest[(*Hence the name, DiD*)] --- # Cholera in the 1850's <table> <thead> <tr> <th style="text-align:left;"> Supplier </th> <th style="text-align:right;"> Death Rate 1849 </th> <th style="text-align:right;"> Death Rate 1854 </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Non-Lambeth Only (Dirty) </td> <td style="text-align:right;"> 134.9 </td> <td style="text-align:right;"> 146.6 </td> </tr> <tr> <td style="text-align:left;"> Lambeth + Others (Mix clean + dirty) </td> <td style="text-align:right;"> 130.1 </td> <td style="text-align:right;"> 84.9 </td> </tr> </tbody> </table> Change for .hi-blue[Lambeth]: `\(y_{L,1854} - y_{L,1849} = 84.9 - 130.1 = -45.2\)` **Q:** Is this all the evidence we need to conclude Cholera comes from water? -- **A:** No, it could reflect anything that changed between 1849 and 1854! -- Change .hi-orange[elsewhere]: `\(y_{NL,1854} - y_{NL,1849} = 146.6 - 134.9 = 11.7\)` Cholera rates were actually **increasing** in places not served by Lambeth over the same time period! -- Estimated treatment effect is `\(\Delta \bar{y}_L - \Delta \bar{y}_{NL} = -45.2 - 11.7 = -56.9\)` --- # Cholera in the 1850's Change .hi-orange[elsewhere]: `\(y_{NL,1854} - y_{NL,1849} = 146.6 - 134.9 = 11.7\)` - This is our estimate for the **counterfactual** - "Ideally" we'd know Cholera rates in 1854 for places served by .hi-blue[Lambeth] if they hadn't switched to clean water - But we only observe data from what actually happened -- Thus, the change .hi-orange[elsewhere] is our approximation of what *would have happened* in areas served by .hi-blue[Lambeth] if they did not switch. -- What are we assuming? -- The **Parallel Trends Assumption**. >That the difference between .hi-blue[Lambeth] and .hi-orange[non-Lambeth] areas would have remained the same if .hi-blue[Lambeth] hadn't switched their water source. --- # Cholera in the 1850's ### Actual outcomes <img src="16-Difference-in-Differences_files/figure-html/cholera_plot-1.png" style="display: block; margin: auto;" /> --- # Cholera in the 1850's ### With our counterfactual <img src="16-Difference-in-Differences_files/figure-html/cholera_plot2-1.png" style="display: block; margin: auto;" /> --- class: inverse, middle # Difference in Differences (DiD) --- # Non-Random Treatment <br> We've talked about binary categorical variables. An important application of .hi-pink[dummy variables] is to study the impact of a treatment. -- The estimation of treatment effects is important in a wide range of fields. .hi-blue[Examples:] * impact of cash transfers on child health * effect of class size on student achievement -- In clinical trials of health interventions, a common question is whether use of a medicine will improve health outcomes. --- # Non-Random Treatment Ideally treatment effects are evaluated using .hi-pink[randomized controlled trials]. -- We capture treatment with a dummy variable and use a simple statistical model `$$Y_i = \beta_0 + \beta_1 D_i + u_i$$` -- for `\(i = 1, \dots, n,\)` where `\(D_i = 1\)` if treated and `\(D_i = 0\)` if not treated, and where `\(y_i\)` is the outcome for individual `\(i\)`. -- **Q:** What are the interpretations of the coefficients `\(\beta_0\)` and `\(\beta_1\)`? -- **Random assignment**: If `\(D_i\)` and `\(u_i\)` are .hi-pink[uncorrelated (A3.)], then OLS estimates will be unbiased. Our effect is the difference in mean outcomes for treated and untreated groups, `\(\hat\beta_1 = \bar y_1 - \bar y_0\)`, called the **differences estimator** --- # Non-Random Treatment Often we are analyzing some _treatment_ that takes place at a particular time, and we have data .hi-pink[before and after] the treatment took place. -- If the policy intervention affected everyone and we have data both in pre- and post-policy periods, might consider using the **differences estimator** > __Problem:__ Assumes that there are not other reasons for the change in mean outcomes before and after the treatment -- In this case the dummy variable `\(D_i\)` in effect stands for the impact of .hi-pink[all factors], including the treatment, that are different between the pre- and post- periods. --- # Non-Random Treatment Since .hi-pink[other factors] may be partially responsible for the change in mean outcomes, the difference estimator will likely be biased (example of exogeneity failing) -- This point emphasizes importance of a control group that does not receive the treatment. Sometimes policies have actual randomization, .hi-blue[(randomized field experiments)]. -- > __Example:__ Oregon Health Plan (OHP) experiment of 2008. Oregon decided to expand coverage of its version of Medicaid to groups not previously eligible, but this expanded coverage was rationed by a lottery to reduce the cost of the program: somewhat under half of those who registered were randomly selected and invited to apply for expanded coverage. -- Since treatment was randomly assigned, `\(E[u_i|D_i]=0\)` --- # DiD Concept Most of the time, we are not so lucky to have real randomization. Instead we often have to use .hi-pink[natural experiments]. -- > __Setting:__ There is a discrete change in policy that affects only part of the population, and that there are both pre- and post-treatment observations for both those who received treatment and those who did not. -- Since the policy change is not distributed randomly, mean outcomes for the treated and control group may differ for a variety of reasons. -- The .hi-pink[difference-in-difference (DiD)] method allows for differences between the treatment and control groups by measuring the treatment effect based on the **change** in outcomes before and after treatment for the treatment group **relative** to the control group. --- # DiD Structure <br> Suppose we have data on specific individuals `\(i = 1,\dots, n\)` in each of two time periods `\(t = 1, 2\)`. A simple statistical formulation of the model is then: -- `$$Y_{it} = \beta_0 + \beta_1 T_t + \beta_2 D_i + \beta_3 (T_t \times D_i) + u_{it}$$` for `\(i = 1,\dots,n,\)` and `\(t = 1, 2\)`. (Note that we have `\(2n\)` data points). -- Here `\(T_t = 1\)` if `\(t = 2\)` and `\(T_t = 0\)` if `\(t = 1\)`, while `\(D_i = 1\)` if individual `\(i\)` receives treatment and `\(D_i = 0\)` if individual `\(i\)` does not receive treatment. --- # DiD Structure In the .hi-pink[pre-treatment period], `\(t = 1\implies T_t=0\)`, we have `$$E(y_{i1} | D_i = 0) = \beta_0 \qquad \text{and} \qquad E(y_{i1} | D_i = 1) = \beta_0 + \beta_2$$` -- We are allowing for the possibility that there was imperfect control, in the sense that treated and untreated may have different pre-treatment means. -- In the .hi-pink[post-treatment period], `\(t = 2\implies T_t=1\)`, we have `$$E(y_{i2} | D_i = 0) = \beta_0 + \beta_1 \quad \text{and} \quad E(y_{i2} | D_i = 1) = \beta_0 + \beta_1 + \beta_2 + \beta_3$$` -- The .hi-pink[treatment effect] corresponds to `\(\beta_3\)`: This is because $$ `\begin{aligned} \text{Diff Treated:} & \ E(y_{i2} | D_i = 1) - E(y_{i1} | D_i = 1) = \beta_1 + \beta_3 \ \ \text{and}\\ \text{Diff Control:} & \ E(y_{i2} | D_i = 0) - E(y_{i1} | D_i = 0) = \beta_1 \end{aligned}` $$ --- # DiD Example _"Monetary Intervention in the Great Depression"_ by **Gary Richardson and William Troost (JPE, 2009)**. -- Consider the 1930s bank failures. Central Bank can prevent bank runs and bank failures by acting as lender of last resort to insolvent banks. -- The twelve different regional Federal Reserve Districts reacted in the 1930s to potential bank failures in different ways. -- * .hi-slate[Atlanta FRB (sixth district)] and .hi-purple[St Louis FRB (eighth district)] followed radically different policies on bank runs * Makes for a natural experiment, comparing outcomes for bank failures in Mississippi banks in the two districts --- # DiD Example ### Banking simplified... - Banks take deposits from savers and then lend that money out to others - They do not hold enough cash on hand to give everyone their savings back if everyone tried to withdraw at once - Bank runs happen when people are afraid the bank is going to fail - Worry about bank failure => Some people widthdraw their money - More withdraws => more likely for the bank to fail - More likely for bank to fail => More people withdraw -- ### Differential policies by fed district The .hi-slate[Sixth District] made credit to banks widely available to ensure they had cash to cover withdraws, while .hi-purple[Eighth District] restricted lending to banks with the idea that it would "weed out" bad banks --- # DiD Example <img src="fed-districts.jpeg" width="80%" style="display: block; margin: auto;" /> Mississippi is cut in half, the .hi-purple[northern part is St. Louis district] and the .hi-slate[southern part is Atlanta district]. -- **We can use this as a natural experiment!** --- # DiD Example R&T analyze this using .hi-pink[Difference-in-differences]. <table> <caption>Bank Losses by Policy</caption> <thead> <tr> <th style="text-align:left;"> Variable </th> <th style="text-align:right;"> 8th District </th> <th style="text-align:right;"> 6th District </th> <th style="text-align:right;"> Diff., 6th-8th </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> No. of Banks open 1930 </td> <td style="text-align:right;"> 165 </td> <td style="text-align:right;"> 135 </td> <td style="text-align:right;"> -30 </td> </tr> <tr> <td style="text-align:left;"> No. of Banks open 1931 </td> <td style="text-align:right;"> 132 </td> <td style="text-align:right;"> 121 </td> <td style="text-align:right;"> -11 </td> </tr> <tr> <td style="text-align:left;"> Changes in banks open </td> <td style="text-align:right;"> -33 </td> <td style="text-align:right;"> -14 </td> <td style="text-align:right;"> 19 </td> </tr> </tbody> </table> Estimated to have saved **19** banks, 14% of .hi-slate[Sixth District] in 1930. -- .smallest[ *Note*: It is equivalent to think of the DiD estimator as - The difference in the change in the treated and the change in the untreated - The change in the difference between treated and untreated pre/post treatment ] --- # DiD Required Assumption A central issue is the .hi-pink[validity] of the control group, which is determined by the .hi-pink[parallel trends] assumption: > In the absence of the _"treatment"_, would the number of open banks in the two districts have been expected to evolve in the same way? <img src="16-Difference-in-Differences_files/figure-html/plot-banks-1.png" width="60%" style="display: block; margin: auto;" /> --- # DiD Interpretation ### Now with a DiD Regression $$ `\begin{aligned} Y_{dt} = \beta_0 + \beta_1 T_t + \beta_2 D_d + \beta_3 (T_t \times D_d) + u_{dt} \end{aligned}` $$ One can use this data to get an estimate of the treatment effect `\(\hat\beta_3\)` and a standard error `\(SE(\hat\beta_3)\)` based on these twelve data points: $$ `\begin{aligned} Y_{dt} = 167 - 49 T_t - 29 D_d + 20.5(T_t \times D_d) + u_{dt} \end{aligned}` $$ Here `\(T_t\)` is coded 1 for 1931 or later, and `\(D_d=1\)` for the 6th District. -- `\(\hat{\beta}_3\)` has `\(t = 1.9\)` which is significant at 10% level using a two-tailed test. This is about the best we can do with twelve data points. --- # DiD Interpretation <img src="16-Difference-in-Differences_files/figure-html/plot-banks-c-1.png" width="90%" style="display: block; margin: auto;" /> The dashed line represents our assumed **counterfactual**. --- # DiD Interpretation Let's do the same .hi-pink[DiD] with other outcome variables! <img src="table5_1.png" width="90%" style="display: block; margin: auto;" /> -- Seems like more liberal credit availability saved a lot of wholesale firms. --- class: inverse, middle # Panel Data --- # Types of data - **Cross sectional**: Observe some set of entity at one particular time - **Time Series**: Observe a single entity over multiple time periods - **Pooled Cross sectional**: Have a sample of entities over multiple time periods, but don't necessarily observe the same entities each period -- .pull-left[ .hi-yellow[Cross-sectional data:] individual `\(i\)` <img src="16-Difference-in-Differences_files/figure-html/cross_sectional_plot-1.png" style="display: block; margin: auto;" /> ] .pull-right[ .hi-purple[Time-series data:] time `\(t\)` <img src="16-Difference-in-Differences_files/figure-html/time_series_plot-1.png" style="display: block; margin: auto;" /> ] -- .hi-pink[*Panel data*] combine these data types/dimensions: individual `\(i\)` **at** time `\(t\)`. --- layout: false class: clear-slide .hi-pink[*Panel data*] combine these data types/dimensions: individual `\(i\)` **at** time `\(t\)`. <img src="16-Difference-in-Differences_files/figure-html/panel_plot-1.png" style="display: block; margin: auto;" /> --- name: definition # Definition .pull-left[ With .hi-pink[*panel data*], we have - .hi-purple[repeated observations] `\((t)\)` - on .hi-yellow[multiple individuals] `\((i)\)`. ] -- .pull-right[ ``` #> state year poverty_rate min_wage #> 1 CA 1990 13.9 4.25 #> 2 CA 2000 12.7 6.25 #> 3 CA 2010 16.3 8.00 #> 4 OR 1990 9.2 4.25 #> 5 OR 2000 10.9 6.50 #> 6 OR 2010 14.2 8.40 #> 7 WA 1990 8.9 4.25 #> 8 WA 2000 10.8 6.50 #> 9 WA 2010 11.5 8.55 ``` ] -- Thus, our regression equation with a panel dataset looks like $$ `\begin{align} y_{\color{#FFA500}{i}\color{#6A5ACD}{t}} = \beta_0 + \beta_1 x_{\color{#FFA500}{i}\color{#6A5ACD}{t}} + u_{\color{#FFA500}{i}\color{#6A5ACD}{t}} \end{align}` $$ for .yellow[individual] `\(\color{#FFA500}{i}\)` in .purple[time] `\(\color{#6A5ACD}{t}\)`. --- # Controlling for unobserved factors We can use panel data to control for any unobserved factors that are constant within a larger group, **a solution to Omitted Variable Bias**. .hi-orange[How?] -- Easy! Just add a dummy variable for the group, and you've controlled for everything that is constant within that group. These are called .hi-orange[fixed effects]. -- ### For example - We can control for an individual's background, which is not changing over time, by adding an individual fixed effect - We can control for national economic conditions, which affect all individuals equally in a particular time period, by adding a time fixed effect --- # Fixed effects model Suppose we have a model `$$y_{it} = \beta_0 + \beta_1 x_{it} + \sum_k \gamma_k Z_i^k + u_{it}$$` where `\(Z_i^1,Z_i^2,...,Z_i^K\)` are `\(K\)` variables that affect `\(y\)`, but are constant within individual `\(i\)`. -- Then we can substitute `\(\alpha_i = \sum_k \gamma_k Z_i^k\)` `$$y_{it} = \beta_0 + \beta_1 x_{it} + \alpha_i + u_{it}$$` where `\(\alpha_i\)` represents the unobserved effect of all of the `\(Z^k\)` variables on `\(y\)` for individual `\(i\)`. --- # Fixed effects model Practically, we can run this regression with a dummy variable for each individual (minus one) `$$y_{it} = \beta_0 + \beta_1 x_{it} + \sum_{i=2}^n\alpha_iA_i + u_{it}$$` where `\(A_i\)` is a dummy variable equal to 1 if the observation comes from individual `\(i\)`. -- **What are the fixed effects doing?** They subtract the mean outcome for each individual `\(y_{it}-\bar{y}_i\)`. Thus, we are looking at .hi-orange[within] variation, not .hi-blue[between] variation -- .hi-blue["Between"] is any variation in our data that can be explained by individuals .hi-orange["Within"] is any variation for an individual from one time period to another --- # We have seen this before... .center[] --- class: inverse, middle # DiD Example, Minimum Legal Drinking Age Laws --- # MLDA Laws This DiD estimates MLDA-induced deaths among 18-20 year olds, from 1970-1983. -- **1933:** End of the federal alcohol Prohibition. Most states regulated the .hi-pink[Minimum Legal Drinking Age] to 21. However, some states including Kansas, New York and North Carolina maintained a drinking age of 18. -- **1971:** Voting ages were reduced to 18, and many states coincided this policy change of MLDA to 18. Arkansas, California, and Pennsylvania are among states that kept MLDA at 21. -- **1984:** National Minimum Drinking Age Act punished states set to 18 by withholding federal highway construction aid. -- .hi-blue[What happened between 1970 and 1984 when drinking age was reduced?] --- # MLDA DiD model ### Alabama and Arkansas Alabama reduced MLDA to 19 in 1975, while Arkansas did not change theirs, let `\(D_s\)` indicate whether the state is Alabama and `\(T_t\)` is indicate whether it is after 1975. .hi-blue[Dependent variable:] death rates of 18-20 year olds in state `\(s\)` and year `\(t\)`. -- `$$Y_{st} = \beta_0 + \beta_1 \text{D}_s + \beta_2 \text{T}_t + \beta_3 (D_s \times T_t) + u_{st},$$` -- .hi-pink[Treatment Effect:] `\(\beta_3\)` measures the *causal* effect of lowering the drinking age on death rates of 18-20 year olds. -- .hi-pink[Key Assumption:] Alabama and Arkansas would have shared parallel trends in their death rates of 18-20 year olds throughout the period of analysis if Alabama had not changed their drinking age. --- # MLDA DiD model ### We can do better! What about the other states? Would we not want to use more observations? Yes! But.. -- * States did not all lower to 18 at the same time, meaning there is no common post-treatment period. * Unobservable differences exist across states, constant across time. * Absense of a common treatment variable in a multi-state setting, since states chose ages of 18,19 and 20. -- To solve for these issues, use .hi-blue[state and year fixed effects] and replace `\(T_t \times D_d\)` with a .hi-blue[common treatment variable], `\(LEGAL_{st}\)`, which measures the proportion of 18-20 year-olds allowed to drink in state `\(s\)` and year `\(t\)`. --- # MLDA DiD model <br> .hi-blue[State-Year Panel Data:] Including District of Col. we have 51 "states" and 14 years, giving us 714 observations. -- The .hi-blue[multistate regression] DiD model looks like: `$$Y_{st} = \alpha_0 + \alpha_1 LEGAL_{st} + \sum_{k=\text{Alaska}}^{\text{Wyoming}} \alpha_k \text{State}_{ks} +\sum_{j=\text{1971}}^{\text{1983}} \alpha_j \text{Year}_{jt} + \nu_{st},$$` where now we are using state and year dummies to capture fixed effects, which uses Alabama as our reference state and 1970 as our reference year. -- Regression results suggest that there was a significant increase in deaths, largely attributed to motor vehicle accidents. --- # MLDA Results <img src="table5_2.png" width="90%" style="display: block; margin: auto;" /> --- # MLDA Assumptions Since we have many states and many years of observations, we can relax the .hi-pink[common trends] assumption. We are worried about differential trends in state death rates that would lead us to falsely attribute that pre-existing trend to our treatment. -- We can add .hi-blue[state trends] to control for this factor: $$ `\begin{aligned} Y_{st} =& \alpha_0 + \alpha_1 LEGAL_{st} + \sum_{k=\text{Alaska}}^{\text{Wyoming}} \alpha_k \text{State}_{ks} +\sum_{j=\text{1971}}^{\text{1983}} \alpha_j \text{Year}_{jt}\\ & \sum_{k=\text{Alaska}}^{\text{Wyoming}} \theta_k (\text{State}_{ks} \times t)+ \varepsilon_{st}, \end{aligned}` $$ Our treatment effect now comes from sharp deviations from an otherwise smooth trend. -- .hi-blue[What does this allow us to address?] --- # MLDA Assumptions <img src="fig5_4.png" width="80%" style="display: block; margin: auto;" /> --- # MLDA Assumptions <img src="fig5_5.png" width="80%" style="display: block; margin: auto;" /> --- # MLDA Assumptions <img src="fig5_6.png" width="80%" style="display: block; margin: auto;" /> --- exclude: true