Skip to content

Commit 00db36b

Browse files
committed
Small slides updates
1 parent 5ca9a66 commit 00db36b

8 files changed

Lines changed: 89 additions & 11 deletions

Labs/Example-Code/stacked_imputation_ex.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ sub_exp <- function(df, e, kappa_pre = 3, kappa_post = 2) {
2424
treat <- (df$adopt_year == e)
2525
post <- (df$year >= df$adopt_year)
2626

27+
# MORE FILTERING HERE (e.g. bordering counties, same census region, etc.)
28+
2729
case_when(
2830
!balance_event_time ~ 0L,
2931
clean_control ~ 1L,
2.73 MB
Binary file not shown.
2.77 MB
Binary file not shown.

Readings/Imbens_2004.pdf

203 KB
Binary file not shown.

Slides/06-Imputation.pdf

3.17 MB
Binary file not shown.

Slides/Tex/06-Imputation.pdf

2.29 MB
Binary file not shown.

Slides/Tex/06-Imputation.tex

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\usepackage{verbatim}
55
\usepackage{bm}
66
\begin{document}
7-
% \imageframe{./lecture_includes/slide_banner.pdf}
7+
\imageframe{./lecture_includes/slide_banner.pdf}
88

99
\section{Imputation in 2x2}
1010

@@ -139,7 +139,7 @@ \section{Imputation with Staggered Treatment Timing}
139139
Units can vary in what year they get treated, denoted by $g$.
140140

141141
\bigskip
142-
Researchers care about the average treatment effect on the treated, $\tau = \expec{\tau_{it}}{d_{it} = 1}$ or perhaps some different average of $\tau_{it}$.
142+
Researchers care about the overall ATT, $\expec{\tau_{it}}{d_{it} = 1}$, or some different average of $\tau_{it}$.
143143
\end{frame}
144144

145145
\begin{frame}{TWFE Model}{Treatment effect heterogeneity}
@@ -168,9 +168,10 @@ \section{Imputation with Staggered Treatment Timing}
168168
y_{it} = \mu_i + \eta_t + \tau d_{it} + \underbrace{u_{it}}_{ \varepsilon_{it} + (\tau_{it} - \tau) d_{it} }
169169
$$
170170

171+
\medskip
171172
The error term now contains the treatment effect heterogeneity.
172173
\begin{itemize}
173-
\item If there is any systematic heterogeneity like we described before, then the covariates (fixed-effects) are correlated with the error term and OLS estimates are biased.
174+
\item If there is any systematic heterogeneity like we described before, then the covariates (fixed-effects) are correlated with the error term and OLS estimates suffer from omitted variables bias.
174175
\end{itemize}
175176
\end{frame}
176177

@@ -181,16 +182,18 @@ \section{Imputation with Staggered Treatment Timing}
181182
y_{it} - \mu_i - \eta_t = \tau_{it} d_{it} + \varepsilon_{it}
182183
$$
183184

185+
\pause
184186
\bigskip
185187
If we regress $y_{it} - \mu_i - \eta_t$ on the dummy variable $d_{it}$, OLS algebra tells us that $\hat{\tau}$ will estimate a simple average of $\tau_{it}$ (plus noise):
186188

187189
$$
188-
\hat{\tau} = \frac{1}{\sum_{(i,t)} d_{it}} \sum_{(i,t)} \left( \tau_{it} d_{it} + \varepsilon_{it} \right) = \text{ATT} + \text{noise}
190+
\hat{\tau} = \frac{1}{N_{post}} \sum_{(i,t)} \left( \tau_{it} d_{it} + \varepsilon_{it} \right) = \text{ATT} + \text{noise},
189191
$$
192+
where $N_{post}$ is the number of post-treatment observations
190193

191194
\pause
192195
\bigskip
193-
Similarly, if we had a set of \emph{mutually-exclusive} event-study variables, $d_{it}^\ell$, we would get averages of $\tau_{it}$ for $(i,t)$ with $g_i - t = \ell$.
196+
Similarly, if we had a set of \emph{mutually-exclusive} event-study dummy variables, $d_{it}^\ell$, we would get averages of $\tau_{it}$ for $(i,t)$ with $g_i - t = \ell$.
194197
\end{frame}
195198

196199
\begin{frame}{Too bad we don't know $\mu$ and $\eta$}
@@ -210,12 +213,19 @@ \section{Imputation with Staggered Treatment Timing}
210213

211214
\bigskip
212215
Under our model, the left-hand side equals:
213-
$$
214-
y_{it} - \hat{\mu}_i - \hat{\eta}_t = \tau_{it} d_{it} + (\mu_i - \hat{\mu}_i) + (\eta_t - \hat{\eta}_t) + \varepsilon_{it}.
215-
$$
216+
\only<1>{
217+
$$
218+
y_{it} - \hat{\mu}_i - \hat{\eta}_t = \tau_{it} d_{it} + (\mu_i - \hat{\mu}_i) + (\eta_t - \hat{\eta}_t) + \varepsilon_{it}.
219+
$$
220+
}\only<2>{
221+
$$
222+
y_{it} - \hat{\mu}_i - \hat{\eta}_t = \tau_{it} d_{it} + \underbrace{(\mu_i - \hat{\mu}_i)}_{\text{mean } 0} + \underbrace{(\eta_t - \hat{\eta}_t)}_{\text{mean } 0} + \varepsilon_{it}.
223+
$$
224+
}
225+
226+
\pause
227+
We have a noisy estimate for $\tau_{it}$, but we are averaging over observations. So what's the problem?
216228

217-
Therefore we have a noisy estimate for $\tau_{it}$, so what's the problem?
218-
219229
\bigskip
220230
\pause
221231
All of the modern diff-in-diff problems (yes all of them) show different ways to interpret the same problem: $\tilde{d}_{it}$.
@@ -230,7 +240,7 @@ \section{Imputation with Staggered Treatment Timing}
230240
$$
231241

232242
\bigskip
233-
Okay, so why don't you just regress $y_{it} - \hat{\mu}_i - \hat{\eta}_t$ on $d_{it}$? Great intuition!
243+
Okay, so why don't you just regress $y_{it} - \hat{\mu}_i - \hat{\eta}_t$ on $d_{it}$? \pause Great intuition!
234244
\end{frame}
235245

236246
\begin{frame}{Two-stage difference-in-differences}
@@ -239,6 +249,7 @@ \section{Imputation with Staggered Treatment Timing}
239249
\bigskip
240250
\textbf{Stage 1:}
241251
Estimate $\mu_i$ and $\eta_t$ using untreated/not-yet-treated observations ($d_{it} = 0$).
252+
\pause
242253
\begin{itemize}
243254
\item Don't include $d_{it} = 1$ since the treatment effects will bias estimates of the fixed effects.
244255
\end{itemize}
@@ -652,6 +663,22 @@ \section{Synthetic Control}
652663
\end{itemize}
653664
\end{frame}
654665

666+
\begin{frame}{Inference in Synthetic Control}
667+
Inference in the classical synthetic control setting is really difficult
668+
\begin{itemize}
669+
\item Only one treated unit; you're not averaging over units so the estimate is subject to random shocks
670+
\end{itemize}
671+
672+
\pause
673+
\bigskip
674+
Two forms of randomization inference are typically used:
675+
\begin{itemize}
676+
\item Randomly shuffle treatment to control units and reestimate synthetic control; want the treated unit to look more extreme than the placebo estimates. The so-called `spaghetti plot'
677+
678+
\item Randomly shuffle time-periods around for treated unit and reestimate synthetic control
679+
\end{itemize}
680+
\end{frame}
681+
655682
\begin{frame}{Implementing Synthetic Control}
656683
My recommendation for synthetic control is \texttt{scpi} package (on R, Stata, and Python)
657684
\begin{itemize}

Slides/Tex/imputation.R

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
library(fixest)
2+
library(tidyverse)
3+
library(did2s)
4+
library(didimputation)
5+
6+
#' # 2x2 Imputation
7+
# %%
8+
data(df_het)
9+
df_het = df_het |>
10+
as_tibble() |>
11+
filter(g == 2010 | g == 0, year == 2009 | year == 2011) |>
12+
mutate(
13+
d_it = (g == 2010) & (year == 2011),
14+
post = year == 2011,
15+
y = dep_var
16+
)
17+
18+
# TWFE estimate
19+
(twfe_est = feols(y ~ i(d_it) | unit + year, data = df_het, vcov = "hc1"))
20+
21+
resids = resid(feols(c(y, d_it) ~ 0 | unit + year, data = df_het))
22+
ytilde = resids[, 1]
23+
dtilde = resids[, 2]
24+
d = as.logical(df_het$d_it)
25+
26+
ytilde[!d]
27+
ytilde[d]
28+
29+
twfe_est = feols(
30+
y ~ 0 + i(d_it, ref = FALSE) + i(post, ref = FALSE) + i(unit),
31+
data = df_het, vcov = "hc1"
32+
)
33+
34+
35+
# E(Y_i1 - Y_i0 | D_i = 0)
36+
df_het |>
37+
mutate(.by = unit, d_y = y[year == 2011] - y[year == 2009]) |>
38+
filter(g == 0 & year == 2011) |>
39+
with(mean(d_y))
40+
coef(twfe_est, keep = "post")
41+
42+
# Y_i0
43+
df_het |>
44+
filter(g == 2010 & year == 2009) |>
45+
select(unit, y) |>
46+
tail()
47+
coef(twfe_est, keep = "unit")["unit::1483"]
48+
49+

0 commit comments

Comments
 (0)