## 8.5 Panel Data Approaches

SW All of Ch. 10 and 13.4

In the previous section, we invoked the assumption of unconfoundedness and were in the setup where $$X$$ was fully observed. But suppose instead that you thought this alternative version of unconfoundedness held \begin{align*} (Y(1),Y(0)) \perp D | (X,W) \end{align*} where $$X$$ were observed random variables, but $$W$$ were not observed. Following exactly the same argument as in the previous section, this would lead to a regression like \begin{align*} Y_i = \alpha D_i + \beta_0 + \beta_1 X_i + \beta_2 W_i + U_i \end{align*} (I’m just including one $$X$$ and one $$W$$ for simplicity, but you can easily imagine the case where there are more.) If $$W$$ were observed, then we could just run this regression, but since $$W$$ is not observed, we run into the problem of omitted variable bias (i.e., if we just ignore $$W$$, we won’t be estimating the causal effect $$\alpha$$)

In this section, we’ll consider the case where a researcher has access to a different type of data called panel data. Panel data is data that follows the same individual (or firm, etc.) over time. In this case, it is often helpful to index variables by time. For example, $$Y_{it}$$ is the outcome for individual $$i$$ in time period $$t$$. $$X_{it}$$ is the value of a regressor for individual $$i$$ in time period $$t$$ and $$D_{it}$$ is the value of the treatment for individual $$i$$ in time period $$t$$. If some variable doesn’t vary over time (e.g., a regressor like race), we won’t use a $$t$$ subscript.

Panel data potentially gives us a way around the problem of not observing some variables that we would like to condition on in the model. This is particularly likely to be the case when $$W$$ does not vary over time. Let’s start with there are exactly two time periods of panel data. In that case, we can write \begin{align*} Y_{it} = \alpha D_{it} + \beta_0 + \beta_1 X_{it} + \beta_2 W_i + U_{it} \end{align*} where we consider the case where $$D$$ and $$X$$ both change over time. Then, defining $$\Delta Y_{it} = Y_{it} - Y_{it-1}$$ (and using similar notation for other variables), notice that \begin{align*} \Delta Y_{it} = \alpha \Delta D_{it} + \beta_1 \Delta X_{it} + \Delta U_{it} \end{align*} which, importantly, no longer involves the unobserved $$W_i$$ and suggests running the above regression and interpreting the estimated version of $$\alpha$$ as an estimate of the causal effect of participating in the treatment.

• Time fixed effects — The previous regression did not include an intercept. It is common in applied work to allow for the intercept to vary over time (i.e., so that $$\beta_0 = \beta_{0,t}$$) which allows for “aggregate shocks” such as recessions or common trends in outcomes over time. In practice, this amounts to just including an intercept in the previous regression, for example,

$\Delta Y_{it} = \underbrace{\theta_t} + \alpha \Delta D_{it} + \beta_1 \Delta X_{it} + \Delta U_{it}$

Often, there may be many omitted, time invariant variables. In practice, these are usually just lumped into a single individual fixed effect — even if there are many time invariant, unobserved variables, we can difference them all out at the same time \begin{align*} Y_{it} &= \alpha D_{it} + \beta_{0,t} + \beta_1 X_{it} + \underbrace{\beta_2 W_{1i} + \beta_3 W_{2i} + \beta_4 W_{3i}} + U_{it} \\ &= \alpha D_{it} + \beta_{0,t} + \underbrace{\eta_i} + U_{it} \end{align*} and we can follow the same strategies as above.

Another case that is common in practice is when there are more than two time periods. This case is similar to the previous one except there are multiple ways to eliminate the unobserved fixed effect. The two most common are the

• Within estimator

To motivate this approach, notice that, if, for each individual, we average their outcomes over time, the we get \begin{align*} \bar{Y}_i = \alpha \bar{D}_i + \beta_1 \bar{X}_i + (\textrm{time fixed effects}) + \bar{U}_i \end{align*} (where I have just written “time fixed effects” to indicate that these are transformed version of original fixed but still show up here.) Subtracting this equation from the expression for $$Y_{it}$$ gives \begin{align*} Y_{it} - \bar{Y}_i = \alpha (D_{it} - \bar{D}_i) + \beta_1 (X_{it} - \bar{X}_i) + (\textrm{time fixed effects}) + U_{it} - \bar{U}_i \end{align*}

This is a feasible regression to estimate (everything is observed here). This is called a within estimator because the terms $$\bar{Y}_i$$, $$\bar{D}_i$$, and $$\bar{X}_i$$ are the within-individual averages-over-time of the corresponding variable.

• First differences

Another approach to eliminating the unobserved fixed effects is to directly consider $$\Delta Y_{it}$$:

\begin{align*} \Delta Y_{it} = \alpha \Delta D_{it} + \beta_1 \Delta X_{it} + \Delta U_{it} \end{align*}

This is the same expression as we had before for the two period case. Only here you would include observations from all available time periods on $$\Delta Y_{it}, \Delta D_{it}, \Delta X_{it}$$ in the regression.

It’s worth mentioning the cases where a fixed effects strategy can break down:

• Unobserved variables vary over time

$Y_{it} = \alpha D_{it} + \beta_0 + \beta_1 X_{it} + \beta_2 \underbrace{W_{it}} + U_{it}$ In this case,

$\Delta Y_{it} = \alpha \Delta D_{it} + \beta_1 \Delta X_{it} + \beta_2 \underbrace{\Delta W_{it}} + \Delta U_{it}$

which still involves the unobserved $$W_{it}$$, and implies that the fixed effects regression will contain omitted variable bias.

• The effect of unobserved variables varies over time

$Y_{it} = \alpha D_{it} + \beta_0 + \beta_1 X_{it} + \underbrace{\beta_{2,t}} W_i + U_{it}$ In this case,

$\Delta Y_{it} = \alpha \Delta D_{it} + \beta_1 \Delta X_{it} + \underbrace{(\beta_{2,t} - \beta_{2,t-1})} W_i + \Delta U_{it}$

which still involves the unobserved $$W_i$$ (even though it doesn’t vary over time) and, therefore, the fixed effects regressions we have been considering will contain omitted variable bias.

Also, the assumption of treatment effect homogeneity can potentially matter a lot in this context. This will particularly be the case when (i) individuals can become treated at different points in time, and (ii) there are treatment effect dynamics (so that the effect of participating in the treatment can vary over time) — both of these are realistic in many applications. This is a main research area of mine and one I am happy to talk way more about.

### 8.5.1 Difference in differences

The panel data approaches that we have been talking about so far are closely related to a natural-experiment type of strategy called difference in differences (DID).

One important difference relative to the previous approach is that DID is typically implemented when some units (these are often states or particular locations) implement a policy at some time period while others do not; and, in particular, we observe some periods before any units participate in the treatment.

Let’s think about the case with exactly two time periods: $$t$$ and $$t-1$$. In this case, we’ll suppose that the outcomes that we observe are \begin{align*} Y_{it} &= D_i Y_{it}(1) + (1-D_i) Y_{it}(0) \\ Y_{it-1} &= Y_{it-1}(0) \end{align*} In other words, in the second period, we observe treated potential outcomes for treated units and untreated potential outcomes for untreated units (this is just like the cross-sectional case above). But in the first period, we observe untreated potential outcomes for all units — because no one is treated yet.

DID is often motivated by an assumption called the parallel trends assumption:

Parallel Trends Assumption \begin{align*} \mathbb{E}[\Delta Y_t(0) | D=1] = \mathbb{E}[\Delta Y_t(0) | D=0] \end{align*} This says that the path of outcomes that individuals in the treated group would have experienced if they had not been treated is the same as the path of outcomes that individual in the untreated group actually experienced.

As before, we continue to be interested in \begin{align*} ATT = \mathbb{E}[Y_t(1) - Y_t(0) | D=1] \end{align*} Recall that the key identification challenge if for $$\mathbb{E}[Y_t(0)|D=1]$$ here, and notice that \begin{align*} \mathbb{E}[Y_t(0) | D=1] &= \mathbb{E}[\Delta Y_t(0) | D=1] + \mathbb{E}[Y_{t-1}(0) | D=1] \\ &= \mathbb{E}[\Delta Y_t(0) | D=0] + \mathbb{E}[Y_{t-1}(0)|D=1] \\ &= \mathbb{E}[\Delta Y_t | D=0] + \mathbb{E}[Y_{t-1}|D=1] \end{align*} where the first equality adds and subtracts $$\mathbb{E}[Y_{t-1}(0)|D=1]$$, the second equality uses the parallel trends assumption, and the last equality holds because all the potential outcomes in the previous line are actually observed outcome. Plugging this expression into the one for $$ATT$$ yields: \begin{align*} ATT = \mathbb{E}[\Delta Y_t | D=1] - \mathbb{E}[\Delta Y_t | D=0] \end{align*} In other words, under parallel trends, the $$ATT$$ can be recovered by comparing the path of outcomes that treated units experienced relative to the path of outcomes that untreated units experienced (the latter of which is the path of outcomes that treated units would have experienced if they had not participated in the treatment).

As above, it is often convenient to estimate $$ATT$$ using a regression. In fact, you can show that (in the case with two periods), $$\alpha$$ in the following regression is equal to the $$ATT$$: \begin{align*} Y_{it} = \alpha D_{it} + \theta_t + \eta_i + v_{it} \end{align*} where $$\mathbb{E}[v_t | D] = 0$$.

### 8.5.2 Computation

The lab in this chapter uses panel data to think about causal effects, so I won’t provide an extended discussion here but rather just mention the syntax for a few panel data estimators. Let’s suppose that you had a data frame that, for the first few rows, looked like (this is totally made up data)

#>   id year         Y       X1 X2
#> 1  1 2019  87.92934 495.4021  1
#> 2  1 2020 102.77429 495.6269  1
#> 3  1 2021 110.84441 495.4844  0
#> 4  2 2019  76.54302 492.8797  1
#> 5  2 2020 104.29125 496.1825  1
#> 6  2 2021 105.06056 492.0129  1

This is what panel data typically looks like — here, we are following a single individual (who is distinguished by their id variable) over three years (from 2019-2021), there is an outcome Y and potential regressors X1 and X2.

There are several packages in R for estimating the fixed effects models that we have been considering. I mainly use plm (for “panel linear models”), so I’ll show you that one and then mention one more.

For plm, if you want to estimate a fixed effects model in first differences, you would use the plm command with the following sort of syntax

library(plm)
plm(Y ~ X1 + X2 + as.factor(year),
data=name_of_data,
effect="individual",
model="fd",
index="id")

We include here as.factor(year) to include time fixed effects, effect="individual" means to include an individual fixed effect, model="fd" says to estimate the model in first differences, and index="id" means that the individual identifier is in the column “id”.

The code for estimating the model using a within transformation is very similar:

plm(Y ~ X1 + X2 + as.factor(year),
data=name_of_data,
effect="individual",
model="within",
index="id")

The only difference is that model="fd" has been replaced with model="within".

Let me also just mention that the estimatr package can estimate a fixed effects model using a within transformation. The code for this case would look like

library(estimatr)

lm_robust(Y ~ X1 + X2 + as.factor(year),
data=name_of_data,
fixed_effects=~id)

I think the advantage of using this approach is that it seems straightforward to get the heteroskedasticity robust standard errors (or cluster-robust standard errors) that are popular in economics (as we have done before for heteroskedasticity robust standard errors for a regression with just cross sectional data). But I am not sure how (or if it is possible) to use estimatr to estimate the fixed effects model in first differences.