class: center, middle, inverse, title-slide .title[ # Panel Estimation ] .subtitle[ ## EC 421, Set 12 ] .author[ ### Edward Rubin ] --- class: inverse, middle # Prologue --- name: schedule # Schedule ## Last time Instrumental variables ## Today **Panel estimation** - what panel data buy us, - fixed effects, - the difference-in-differences estimator, - *brief extension:* the synthetic-controls estimator. --- layout: false class: inverse, middle # Panel estimation --- layout: true # Panel estimation --- name: panel_intro ## Introduction Until now, we mostly used one of two data structures: -- 1. .hi-orange[Cross section:] many units, one period, -- 2. .hi-purple[Time series:] one unit, many periods. -- A .hi[panel] gives us both: - .orange[units] indexed by `\(\color{#FFA500}{i}\)`, - .purple[(time) periods] indexed by `\(\color{#6A5ACD}{t}\)`, - outcomes and regressors like `\(\color{#e64173}{y_{\color{#FFA500}{i}\color{#6A5ACD}{t}}}\)` and `\(\color{#e64173}{x_{\color{#FFA500}{i}\color{#6A5ACD}{t}}}\)`. --- ## Example Consider the following panel of six observations: .pull-left[ ``` #> Unit Year y_it x_it #> <char> <num> <num> <num> #> 1: A 1 10 2 #> 2: A 2 11 3 #> 3: A 3 13 4 #> 4: B 1 7 1 #> 5: B 2 8 1 #> 6: B 3 9 2 ``` ] --- ## Example Consider the following panel of six observations: .pull-left[ ``` #> Unit Year y_it x_it #> <char> <num> <num> <num> *#> 1: A 1 10 2 *#> 2: A 2 11 3 *#> 3: A 3 13 4 #> 4: B 1 7 1 #> 5: B 2 8 1 #> 6: B 3 9 2 ``` ] .pull-right[ We observe the .orange[same unit] repeatedly. ] We can compare unit A to itself .hi-purple[over time], not just A to B<br>(potentially helping with *selection bias*). --- ## Example Consider the following panel of six observations: .pull-left[ ``` #> Unit Year y_it x_it #> <char> <num> <num> <num> *#> 1: A 1 10 2 #> 2: A 2 11 3 #> 3: A 3 13 4 *#> 4: B 1 7 1 #> 5: B 2 8 1 #> 6: B 3 9 2 ``` ] .pull-right[ Similarly, we observe the .purple[period] across .orange[units]. ] This feature lets us control for shocks shared across .orange[units] at a given .purple[time]. --- ## The benefits of panels Panels help solve (some) econometric problems because they allow us to -- - control for .b.orange[time-invariant differences] across units<br>.grey-light.it[removes selection bias from cross-sectional differences across units] -- - implicitly study .b.purple[changes]<br>.grey-light.it[not just levels] -- - .note[related:] evaluate policies using their .b.purple[timing]<br>.grey-light.it[policy-timing is often more plausibly exogeneous than policy existence] -- Panel methods are workhorses of economics and public policy. --- ## Panels are helpful—not magical Panel data *can* be helpful for estimating causal effects, <br>but they can still cause problems without careful use. -- - We need (sufficient) .it.orange[within variation] in `\(\color{#FFA500}{x_{it}}\)`.<br>.it[I.e.,] `\(x_{it}\)` must change meaningfully through time for some units. - .purple[Time-varying] omitted variables can cause bias. - A .orange[unit]'s disturbances `\(u_{\color{#FFA500}{i}\color{#6A5ACD}{t}}\)` are often correlated over .purple[time]. - Attrition and missing periods can matter—as can measurement error. .grey-light.it[(Any tool can be misused.)] --- name: pooled_problem ## The problem with pooled OLS Suppose you're interested in a simple linear regression model `$$y_{it} = \beta_0 + \color{#e64173}{\beta_1} x_{it} + u_{it}$$` and have .b.slate[panel data] (with individual `\(i\)` and time `\(t\)`). -- Let the disturbance combine (1) .orange[unit]-specific factor `\(\color{#FFA500}{\alpha_i}\)` and (2) error `\(\color{#2b59c3}{v_{it}}\)` $$ `\begin{align} u_{it} = \color{#FFA500}{\alpha_i} + \color{#2b59c3}{v_{it}} \end{align}` $$ -- If `\(\mathop{\text{Cov}}\left( x_{it}, \color{#FFA500}{\alpha_i} \right) \neq 0\)`, then OLS may be biased. .grey-vlight.it[(Think OVB.)] -- .attn[Standard OLS estimates] of `\(\color{#e64173}{\beta_1}\)` (*i.e.*, without FEs) will reflect both - .it[between-unit differences] `\(\color{#FFA500}{\alpha_i}\)`, - .it[actual changes] in `\(x_{it}\)`. .note[(We want to isolate this last part.)] --- ## Introducing *fixed effects* .note[The solution:] Let each .orange[unit] have its own intercept `\(\color{#FFA500}{\alpha_i}\)`,<br> and each .purple[time period] have its own intercept `\(\color{#6A5ACD}{\lambda_t}\)`: `$$y_{it} = \beta_1 x_{it} + \color{#FFA500}{\alpha_i} + \color{#6A5ACD}{\lambda_t} + u_{it}$$` These .orange[unit]- and .purple[period]-specific intercepts are called .attn[fixed effects]. -- ``` #> Unit Year y_it x_it Unit_A Unit_B Year_1 Year_2 Year_3 #> <char> <num> <num> <num> <num> <num> <num> <num> <num> #> 1: A 1 10 2 1 0 1 0 0 #> 2: A 2 11 3 1 0 0 1 0 #> 3: A 3 13 4 1 0 0 0 1 #> 4: B 1 7 1 0 1 1 0 0 #> 5: B 2 8 1 0 1 0 1 0 #> 6: B 3 9 2 0 1 0 0 1 ``` --- ## Fixed effects in action .qa[Q] So what are these fixed effects (FE) doing? -- Remember the old interpretation of coefficients on binary variables? -- .qa[A] These fixed effects *absorb* - `\(\color{#FFA500}{\alpha_i}\)`: all time-invariant .orange[differences across units],<br>.grey-light.it[(including selection bias from cross-sectional differences)] - `\(\color{#6A5ACD}{\lambda_t}\)`: all common shocks at a given .purple[time]. -- The .attn[(two-way) fixed-effects estimator] (OLS that includes unit and time FEs) <br>estimates effects using .pink.it[within-unit variation]—net of common time shocks. --- ## The *within* transformation For intuition, focus on unit-level fixed effects. `$$y_{it} = \beta_0 + \beta_1 x_{it} + \alpha_i + u_{it}$$` -- Take the average of this equation for unit `\(i\)` across all periods... `$$\overline{y}_i = \beta_0 + \beta_1 \overline{x}_i + \alpha_i + \overline{u}_i$$` -- Finally, subtract the unit mean from both sides of the original equation. <br>(This step is what our unit-level fixed effects are doing.) `$$y_{it} - \overline{y}_i = \beta_1 \left( x_{it} - \overline{x}_i \right) + \left( u_{it} - \overline{u}_i \right)$$` -- .hi[So what?] Unit-specific FEs identify `\(\beta_1\)` using .attn[within-unit variation] in `\(x_{it}\)`. <br>.grey-vlight.it[(The same logic applies to time FEs.)] --- ## Fixed-effects questions Fixed effects .b[do not] ask questions like <br>.white[FE] .note[Why is unit A different from unit B?] <br>.grey-light.it.slab[In fact, they try to absorb cross-unit differences.] -- Fixed effects also .b[do not] ask questions like <br>.white[FE] .note[When period 1 had a shock, how did all units' outcomes change?] <br>.grey-light.it.slab[They try to absorb common (shared) time shocks.] -- Fixed effects .b[do] ask questions like <br>.white[FE] .note[When unit A changed its value of] `\(x_{it}\)`, .note[how did its] `\(y_{it}\)` .note[change?] <br>.grey-light.it.slab[This is the "within" variation.] --- ## Example: State minimum wage laws Suppose we want to estimate the effect of min. wage laws on employment `$$\text{Employment}_{it} = \beta_1 \text{(Min. Wage)}_{it} + \alpha_i + \lambda_t + u_{it}$$` with a .orange[state] (`\(\color{#FFA500}{i}\)`) by .purple[year] (`\(\color{#6A5ACD}{t}\)`) panel of employment and min. wage data. -- - `\(\alpha_i\)` absorbs time-invariant, cross-state differences; - `\(\lambda_t\)` absorbs national shocks in year `\(t\)`. -- .qa[Q] Should we worry that some states have higher min. wage than others? -- <br>.qa[A] No. `\(\alpha_i\)` absorbs those differences. The FE estimator estimates using within-state variation in min. wage. --- ## Example: State minimum wage laws Suppose we want to estimate the effect of min. wage laws on employment `$$\text{Employment}_{it} = \beta_1 \text{(Min. Wage)}_{it} + \alpha_i + \lambda_t + u_{it}$$` with a .orange[state] (`\(\color{#FFA500}{i}\)`) by .purple[year] (`\(\color{#6A5ACD}{t}\)`) panel of employment and min. wage data. - `\(\alpha_i\)` absorbs time-invariant, cross-state differences; - `\(\lambda_t\)` absorbs national shocks in year `\(t\)`. .qa[Q] What if some *years* have lower emp. than others (recessions)? -- <br>.qa[A] Still not worried! `\(\lambda_t\)` absorbs *shared* shocks. --- ## Example: State minimum wage laws Suppose we want to estimate the effect of min. wage laws on employment `$$\text{Employment}_{it} = \beta_1 \text{(Min. Wage)}_{it} + \alpha_i + \lambda_t + u_{it}$$` with a .orange[state] (`\(\color{#FFA500}{i}\)`) by .purple[year] (`\(\color{#6A5ACD}{t}\)`) panel of employment and min. wage data. - `\(\alpha_i\)` absorbs time-invariant, cross-state differences; - `\(\lambda_t\)` absorbs national shocks in year `\(t\)`. .qa[Q] So what should we worry about? -- <br>.qa[A] We should worry about .attn[time-varying differences between states]. *E.g.*, if some states have faster-growing economies and also raise their minimum wages. --- ## What FE means in that example In the minimum-wage panel, fixed effects (FEs) net out factors like - state geography, - long-run industry mix, - baseline labor-market conditions, - permanent political differences. -- `$$\text{Employment}_{it} = \color{#e64173}{\beta_1} \text{(Min. Wage)}_{it} + \alpha_i + \lambda_t + u_{it}$$` With FEs, `\(\color{#e64173}{\hat{\beta}_1}\)` comes from .b.pink[states that change their minimum wage], relative to their own histories and common national trends. --- layout: false class: clear, middle Let's see a graphical example.<br>.grey-vlight[(Simulated data but real FE issues.)] --- layout: false class: clear, middle <img src="slides_files/figure-html/fe-raw-plot1-1.svg" style="display: block; margin: auto;" /> The dark line is .b.slate[pooled OLS]—a regression without fixed effects. <br> Here, states with higher min. wage laws have higher employment rates. --- layout: false class: clear, middle <img src="slides_files/figure-html/fe-raw-plot2-1.svg" style="display: block; margin: auto;" /> However, the .b.purple[within-state relationships] tell another story. <br> The FE estimator focuses on this var.—.it[absorbing] cross-state differences. --- layout: false class: clear, middle <img src="slides_files/figure-html/fe-raw-plot3-1.svg" style="display: block; margin: auto;" /> Integrating .b.purple[fixed effects], the relationship flips.<br>States that raise their minimum wage see lower teen employment. --- layout: false class: clear, middle <img src="slides_files/figure-html/fe-raw-plot4-1.svg" style="display: block; margin: auto;" /> This *flipped* relationship is an example of .attn[Simpson's paradox]—when a relationship reverses after controlling for *"group"*. --- # Panel estimation ## `fixest` syntax Now you know the intution, logic, and mechanics of fixed effects. You also now understand the `fix` part of the `fixest` package. To specify FEs: use `lm` syntax along with `|` followed by the FEs. ``` r feols( * teen_emp ~ min_wage | state + year, cluster = ~ state, data = mw_df ) ``` Here we have fixed effects for .orange[state] and .purple[year]. --- layout: false class: clear .b.mono.pink[Output] `feols` output for the *plain* OLS model .it[vs.] the FE model. ``` *#> est_ols est_fe #> Dependent Var.: teen_emp teen_emp #> #> Constant 21.3*** (3.00) #> min_wage 2.93*** (0.345) -1.44*** (0.196) #> Fixed-Effects: --------------- ---------------- #> state No Yes #> year No Yes #> _______________ _______________ ________________ #> S.E.: Clustered by: state by: state #> Observations 320 320 #> R2 0.48037 0.96360 #> Within R2 -- 0.13134 #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` --- layout: false class: clear .b.mono.pink[Output] `feols` output for the *plain* OLS model .it[vs.] the FE model. ``` #> est_ols est_fe #> Dependent Var.: teen_emp teen_emp #> #> Constant 21.3*** (3.00) *#> min_wage 2.93*** (0.345) -1.44*** (0.196) #> Fixed-Effects: --------------- ---------------- #> state No Yes #> year No Yes #> _______________ _______________ ________________ #> S.E.: Clustered by: state by: state #> Observations 320 320 #> R2 0.48037 0.96360 #> Within R2 -- 0.13134 #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` Both `\(\color{#e64173}{\hat{\beta}_1}\)` are stat. significant, but they tell .pink[very different stories]. --- layout: false class: clear .b.mono.pink[Output] `feols` output for the *plain* OLS model .it[vs.] the FE model. ``` #> est_ols est_fe #> Dependent Var.: teen_emp teen_emp #> *#> Constant 21.3*** (3.00) #> min_wage 2.93*** (0.345) -1.44*** (0.196) #> Fixed-Effects: --------------- ---------------- #> state No Yes #> year No Yes #> _______________ _______________ ________________ #> S.E.: Clustered by: state by: state #> Observations 320 320 #> R2 0.48037 0.96360 #> Within R2 -- 0.13134 #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` .qa[Q] Why is there .pink[no intercept] `\((\beta_0)\)` in the FE model? -- <br> .qa[A] The .pink[fixed effects are collinear] with the intercept—they each provide a separate intercept for each unit and time period. --- layout: false class: clear .b.mono.pink[Output] `feols` output for the *plain* OLS model .it[vs.] the FE model. ``` #> est_ols est_fe #> Dependent Var.: teen_emp teen_emp #> #> Constant 21.3*** (3.00) #> min_wage 2.93*** (0.345) -1.44*** (0.196) #> Fixed-Effects: --------------- ---------------- #> state No Yes #> year No Yes #> _______________ _______________ ________________ #> S.E.: Clustered by: state by: state #> Observations 320 320 #> R2 0.48037 0.96360 *#> Within R2 -- 0.13134 #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` .qa[Q] What is .pink.b[*within* R.super[2]]? -- <br> .qa[A] It is the `\(R^2\)` of the regression .pink[after accouting for the FEs]: how much of the outcome's variation regressors explain, *after controlling for FEs*. --- layout: false class: clear .b.mono.pink[Output] `feols` output for the *plain* OLS model .it[vs.] the FE model. ``` #> est_ols est_fe #> Dependent Var.: teen_emp teen_emp #> #> Constant 21.3*** (3.00) #> min_wage 2.93*** (0.345) -1.44*** (0.196) #> Fixed-Effects: --------------- ---------------- #> state No Yes #> year No Yes #> _______________ _______________ ________________ #> S.E.: Clustered by: state by: state #> Observations 320 320 *#> R2 0.48037 0.96360 #> Within R2 -- 0.13134 #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ``` The FE model has as high `\(\color{#e64173}{R^2}\)` because fixed effects explain a lot of variation (in essence, means of states and years). --- layout: false # Panel estimation ## Summary Fixed effects help one key problem: .hi[time-invariant omitted variables]. -- But FEs .b.slate[do not] solve *all* causal problems, *e.g.*, - time-varying confounders, - reverse causality - measurement error, - poor measurement of treatment timing, - weak within variation. As with *all* econometric tools, careful use is required. --- layout: true # Difference-in-differences --- class: inverse, middle --- name: did_intuition ## Core idea .attn[Difference-in-differences] (DiD).super.pink[†] is a popular panel-data approach for estimating causal effects of policies/events. .footnote[.pink[†] Also called .it[double-differences] or .it[diff-in-diff]. Increasingly combined with .it[two-way fixed effects (TWFE)].] DiD compares observations across two dimensions: 1. .b.purple[Group:] comparing - .purple.it[treated] individuals (potentially affected by the policy) - .purple.it[control] individuals (unaffected by the policy) 2. .b.orange[Time:] comparing - .orange.it[before] the policy takes effect .grey-vlight.it[(pre-treatment)] - .orange.it[after] the policy takes effect .grey-vlight.it[(post-treatment)] --- ## Intuition DiD functions by taking the difference between two differences: -- 1. Δ.b[Y̅.sub.orange.tran50[Pre]] `\(=\)` .b[Y̅](.purple[Trt]; .orange.tran50[Pre]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange.tran50[Pre]) <br> the average difference between .purple[trt.] and .purple.tran50[control] .b.orange.tran50[before] the policy, <br> accounting for pre-existing differences between the groups; -- 2. Δ.b[Y̅.sub.orange[Post]] `\(=\)` .b[Y̅](.purple[Trt]; .orange[Post]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange[Post]) <br> the average difference between .purple[trt.] and .purple.tran50[control] .b.orange[after] the policy, <br> which includes pre-existing differences *and* the .pink[treatment effect]. -- The .attn[DiD estimate] is the difference between these differences <br> .pink[τ̂] `\(=\)` Δ.b[Y̅.sub.orange[Post]] `\(-\)` Δ.b[Y̅.sub.orange.tran50[Pre]] <br> .note[I.e.,] how much did the .purple[trt]-.purple.tran50[control] difference change from .orange.tran50[pre] to .orange[post]? --- layout: false class: clear .mono.b.slate[Ex.] Two .purple[groups (trt/ctrl)] and two .orange[time periods (pre/post policy)]. ``` #> Group Period Mean #> <char> <char> <num> #> 1: Treated Pre 1.965 #> 2: Control Pre 0.323 #> 3: Treated Post 6.172 #> 4: Control Post 1.036 ``` --- layout: false class: clear .mono.b.slate[Ex.] Two .purple[groups (trt/ctrl)] and two .orange[time periods (pre/post policy)]. ``` #> Group Period Mean #> <char> <char> <num> *#> 1: Treated Pre 1.965 *#> 2: Control Pre 0.323 #> 3: Treated Post 6.172 #> 4: Control Post 1.036 ``` 1. Δ.b[Y̅.sub.orange.tran50[Pre]] `\(=\)` .b[Y̅](.purple[Trt]; .orange.tran50[Pre]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange.tran50[Pre]) `\(=\)` 1.642. --- layout: false class: clear .mono.b.slate[Ex.] Two .purple[groups (trt/ctrl)] and two .orange[time periods (pre/post policy)]. ``` #> Group Period Mean #> <char> <char> <num> #> 1: Treated Pre 1.965 #> 2: Control Pre 0.323 *#> 3: Treated Post 6.172 *#> 4: Control Post 1.036 ``` 1. Δ.b[Y̅.sub.orange.tran50[Pre]] `\(=\)` .b[Y̅](.purple[Trt]; .orange.tran50[Pre]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange.tran50[Pre]) `\(=\)` 1.642. 2. Δ.b[Y̅.sub.orange[Post]] `\(=\)` .b[Y̅](.purple[Trt]; .orange[Post]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange[Post]) `\(=\)` 5.136 --- layout: false class: clear .mono.b.slate[Ex.] Two .purple[groups (trt/ctrl)] and two .orange[time periods (pre/post policy)]. ``` #> Group Period Mean #> <char> <char> <num> #> 1: Treated Pre 1.965 #> 2: Control Pre 0.323 #> 3: Treated Post 6.172 #> 4: Control Post 1.036 ``` 1. Δ.b[Y̅.sub.orange.tran50[Pre]] `\(=\)` .b[Y̅](.purple[Trt]; .orange.tran50[Pre]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange.tran50[Pre]) `\(=\)` 1.642. 2. Δ.b[Y̅.sub.orange[Post]] `\(=\)` .b[Y̅](.purple[Trt]; .orange[Post]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange[Post]) `\(=\)` 5.136 The .attn[DiD estimate]—the difference between these differences <br> .pink[τ̂] `\(=\)` Δ.b[Y̅.sub.orange[Post]] `\(-\)` Δ.b[Y̅.sub.orange.tran50[Pre]] `\(=\)` 3.494 --- layout: false class: clear .note[Note] You can also write the DiD estimator as two other differences, .pink[τ̂] `\(=\)` Δ.b[Y̅.sub.orange[Post]] `\(-\)` Δ.b[Y̅.sub.orange.tran50[Pre]] -- .white[τ̂] `\(=\)` `\(\big[\)` .b[Y̅](.purple[Trt]; .orange[Post]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange[Post]) `\(\big]\)` `\(-\)` `\(\big[\)` .b[Y̅](.purple[Trt]; .orange.tran50[Pre]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange.tran50[Pre]) `\(\big]\)` -- .white[τ̂] `\(=\)`.b[Y̅](.purple[Trt]; .orange[Post]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange[Post]) `\(-\)` .b[Y̅](.purple[Trt]; .orange.tran50[Pre]) `\(+\)` .b[Y̅](.purple.tran50[Ctrl]; .orange.tran50[Pre]) -- .white[τ̂] `\(=\)` `\(\big[\)` .b[Y̅](.purple[Trt]; .orange[Post]) `\(-\)` .b[Y̅](.purple[Trt]; .orange.tran50[Pre]) `\(\big]\)` `\(-\)` `\(\big[\)` .b[Y̅](.purple.tran50[Ctrl]; .orange[Post]) `\(-\)` .b[Y̅](.purple.tran50[Ctrl]; .orange.tran50[Pre]) `\(\big]\)` -- .white[τ̂] `\(=\)` Δ.b[Y̅].sub.purple[Trt] `\(-\)` Δ.b[Y̅].sub.purple.tran50[Ctrl] .note[I.e.,] the change in the .purple[treated group] (.orange[post] `\(-\)` .orange.tran50[pre]) relative to <br> the change in the .purple.tran50[control group]. We're using the .purple.tran50[control group's .b[change]] as a .b[counterfactual] for <br> the .purple[treated group's .b[change]] had it not received treatment. --- layout: true # Difference-in-differences --- ## Classic example: Card and Krueger (1994) One famous DiD [application](https://davidcard.berkeley.edu/papers/njmin-aer.pdf) estimates the .b.slate[impact of increasing the minimum wage on fast-food employment]. - .note[Who:] .purple[New Jersey (trt)] *vs.* .purple.tran50[Pennsylvania (ctrl)] - .note[When:] .orange.tran50[before 01 April 1992 (pre)] *vs.* .orange[after 01 April 1992 (post)] DiD estimates .grey-vlight.it[(both questions = same answer)] 1. How did NJ-PA empl. diff. change after the policy, relative to before? 2. How did NJ's empl. change after the policy relative to PA's change? -- .note[Key assumption:] PA needs to be a good counterfactual for NJ. In the absence of the policy, NJ and PA would have followed the same empl. trends. --- ## DiD as a regression With two groups and two periods `$$y_{it} = \beta_0 + \beta_1 \color{#6A5ACD}{\text{Trt}_i} + \beta_2 \color{#FFA500}{\text{Post}_t} + \delta \left( \color{#6A5ACD}{\text{Trt}_i} \times \color{#FFA500}{\text{Post}_t} \right) + u_{it}$$` where `\(\color{#6A5ACD}{\text{Trt}_i}\)` and `\(\color{#FFA500}{\text{Post}_t}\)` are binary indicators for the .purple[treated group] and .orange[post-treatment period]. The interaction asks if if the .orange[post] change in the .purple[treated group] differs from the .orange[post] change in the .purple.tran50[control group]: the .attn[treatment effect]. -- With panel data, we often write `$$y_{it} = \alpha_i + \lambda_t + \delta D_{it} + u_{it}$$` where `\(D_{it}=1\)` only for treated units after treatment starts. --- layout: false class: clear <img src="slides_files/figure-html/did-plot1-1.svg" style="display: block; margin: auto;" /> .b.slate[DiD in pictures] Starting with time series for each unit. <br> .grey-vlight.it[(Treatment starts between periods 5 and 6.)] --- class: clear <img src="slides_files/figure-html/did-plot2-1.svg" style="display: block; margin: auto;" /> Here we have .b.purple[group]-by-.b.orange[time] means. --- class: clear <img src="slides_files/figure-html/did-plot3-1.svg" style="display: block; margin: auto;" /> The .attn[DiD estimate] compares the .b.orange.tran50[pre-trt] difference to the .b.orange[post-trt] diff. --- class: clear <img src="slides_files/figure-html/did-plot4-1.svg" style="display: block; margin: auto;" /> The difference in the .b.orange.tran50[pre-trt] and .b.orange[post-trt] diffs is the .attn[DiD estimate]. --- class: clear .b[DiD in `fixest`] ``` r did_mod = feols( y ~ i(post, treat, ref = 0) | id + period, cluster = 'id', data = base_did ) ``` -- ``` #> OLS estimation, Dep. Var.: y #> Observations: 1,080 #> Fixed-effects: id: 108, period: 10 #> Standard-errors: Clustered (id) #> Estimate Std. Error t value Pr(>|t|) *#> post::1:treat 3.49339 0.521434 6.69959 1.0069e-09 *** #> --- #> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 #> RMSE: 4.74465 Adj. R2: 0.202735 #> Within R2: 0.032761 ``` The interaction btn .orange[post] and .purple[treat] is the .attn[DiD estimate] of the trt effect. --- layout: true # Difference-in-differences --- ## The key DiD assumption DiD relies upon a critical assumption often called .attn[parallel trends]: > In the absence of treatment, treated and control units would have followed the .pink[same average trend]. Again, we're assuming that the trend of the control units provide <br> a .b.slate[good counterfactual] for the treated group. --- ## What threatens DiD? So what violates this .note[parallel trends] assumption? -- - treated units were already on a different trend, - anticipation changes behavior before treatment, - other shocks hit treated units at the same time as treatment. -- What else can *mess up* DiD estimates? - standard errors ignore within-unit dependence, - measurement error, - spillovers from trt to control, - dynamic treatment effects, - het trt effects *and* het trt timing... --- ## DiD's place in the toolbox DiD is especially useful when - treatment .orange[timing] is clear, - .purple[treatment definition] is clear, - you have good .orange[pre-treatment] data - .purple.tran50[ctrl group] provide a plausible counterfactual for .purple[trt group], - the .pink[treatment effect] is tied to a discrete policy or event. -- .qa[Q] What are the other options? -- <br> .qa[A] Synthetic control and friends—build a weighted average of control units to better match the treated unit's pre-treatment path. --- ## Takeaways Key concepts from panel estimation, FEs, and DiD: - .b.slate[Panel data] let us compare a unit to itself .b.purple[over time]. - .b.slate[Fixed effects] remove .b.orange[time-invariant omitted variables]. - `\(\implies\)` .b.slate[Identifying variation] is .b.purple[within variation]. - .b.slate[DiD] focuses on how trt-ctrl .b.slate[differences] change over time. Panels can certainly help, but they still depend on strong assumptions.