# Difference-in-differences and control variables

Im currently processing a bigger assignment, and I'm trying to reproduce the following table, which are difference-in-differences (DD) estimates of income change on voter turnout. However, as far as I'm concerned, control variables aren't necessary in DD models. I have some questions, which I hope some of you might have som good answers on.

1. I'm wondering why there are included (to me) tons of controls in tabel 1, and is it necessary, when running DD?

2. As can be seen in the note, there are neighborhood-by-year fixed effects included. But how is that calculated?

• Welcome. Please provide a reference for those not familiar with the paper. Jul 22 at 16:54

I'm wondering why there are included (to me) tons of controls in tabel 1, and is it necessary, when running DD?

The 'generalized' difference-in-differences estimator does not adjust for everything. The unit fixed effects adjust for all factors that do not change over time within a panel unit, whereas the time fixed effects adjust for the common shocks affecting all units within a time period. But note how including separate fixed effects for unit and time does not adjust for the factors that vary over both of these dimensions! It is advisable to include time-varying controls at the level where treatment is administered, if any. You can even adjust for covariates at the individual level, which may reduce the residual variance. Read here for more information on why we should include control variables in a difference-in-differences applications.

As can be seen in the note, there are neighborhood-by-year fixed effects included. But how is that calculated?

In essence, it's the interaction of indicators for neighborhood with individual year dummies. What we really care about is the product of the two terms, which is only equal to 1 if the observation is in both a particular neighborhood and year (0 otherwise), hence the label "neighborhood-by-year" effect. For example, 20 neighborhoods observed over six years would result in $$20 \times 6 = 120$$ neighborhood-year effects.

But let's unpack that a bit. The year fixed effects—alone—model the common time shocks affecting all spatial units in the same way. In certain circumstances, though, we may suspect that the shocks exhibit variability across space and time. In columns (1), (3), and (4), the neighborhood-by-year effects allow for these yearly shocks to vary by neighborhood—and year. In other words, they allow different neighborhoods to follow different time trends. Civic engagement may vary widely by geography, so it appears the authors include the neighborhood-by-year effect to compute counterfactual time trends among households situated in similar areas. This is a reasonable modeling strategy when your exposure of interest is concentrated over rather large aerial units (i.e., cities, states, countries, etc.). Temporal shocks may have a differential impact by region, and so the neighborhood-by-year effect is that 'special effect' a neighborhood has, in combination with a specific year, on their outcome of interest. In short, it's modeling the combined effects of neighborhood-year unobservables on the regressand.

To achieve this in base R, multiply the indicators for neighborhood with the year dummies directly, or create a concatenated version of the two variables and let software 'dummy out' all the "neighborhood-year" pairs for you. Let's assume y is voter turnout and x is the principal variable of interest (e.g., logged household income). I didn't give their paper a full read, but I assume they estimated a spatial fixed effect at a lower level of aggregation, say at the voter/household level. Let's assume your main specification includes household and year fixed effects. As a robustness check, you also estimate a neighborhood-by-year effect and adjust for obvious individual-/household-/precinct-level covariates. If your controls vary over time, then you should include them!

# Assume we have data at the voter/household level

# The function as.factor() 'dummies out' the categorical levels for you
# The dummies represent the following:

# as.factor(household)                    = household effects
# as.factor(year)                         = year effects
# as.factor(neighborhood)*as.factor(year) = neighborhood-by-year effects

# 1 - Interacting neighborhood with year returns a separate effect for all neighborhood-year combinations

lm(y ~ x + as.factor(household) + as.factor(year) + as.factor(neighborhood)*as.factor(year) + covariates + data = ...)

# 2 - Concatenate the neighborhood and year columns (i.e., neighborhood-year variable) and software will 'dummy out' all the neighborhood-year levels

lm(y ~ x + as.factor(household) + as.factor(year) + as.factor(neighborhood_year) + covariates + data = ...)


In the former equation, the constituent elements of the product term (i.e., neighborhood dummies) may be collinear with a fixed effect at a lower level (i.e., individual/voter/household/district fixed effects), but this shouldn't concern you. More often than not a 'region $$\times$$ time' effect is used as a robustness check. In other words, we're assessing the sensitivity of x under alternative specifications.

In Stata, this is achieved fairly easily using i.neighborhood#i.year. The use of # returns a separate effect for each possible combination of neighborhood and year, which is what you want. It is also worth noting that with voter/household level data, the neighborhood-by-year effect doesn't chew up all your degrees of freedom.