**Open Review**. We want your feedback to make the book better for you and other students. You may annotate some text by selecting it with the cursor and then click the on the pop-up menu. You can also see the annotations of others: click the in the upper right hand corner of the page

## 10.4 Regression with Time Fixed Effects

Controlling for variables that are constant across entities but vary over time can be done by including time fixed effects. If there are *only* time fixed effects, the fixed effects regression model becomes \[Y_{it} = \beta_0 + \beta_1 X_{it} + \delta_2 B2_t + \cdots + \delta_T BT_t + u_{it},\] where only \(T-1\) dummies are included (\(B1\) is omitted) since the model includes an intercept. This model eliminates omitted variable bias caused by excluding unobserved variables that evolve over time but are constant across entities.

In some applications it is meaningful to include both entity and time fixed effects. The *entity and time fixed effects model* is \[Y_{it} = \beta_0 + \beta_1 X_{it} + \gamma_2 D2_i + \cdots + \gamma_n DT_i + \delta_2 B2_t + \cdots + \delta_T BT_t + u_{it} .\] The combined model allows to eliminate bias from unobservables that change over time but are constant over entities and it controls for factors that differ across entities but are constant over time. Such models can be estimated using the OLS algorithm that is implemented in `R`.

The following code chunk shows how to estimate the combined entity and time fixed effects model of the relation between fatalities and beer tax, \[FatalityRate_{it} = \beta_1 BeerTax_{it} + StateEffects + TimeFixedEffects + u_{it}\] using both `lm()` and `plm()`. It is straightforward to estimate this regression with `lm()` since it is just an extension of (10.6) so we only have to adjust the `formula` argument by adding the additional regressor `year` for time fixed effects. In our call of `plm()` we set another argument `effect = “twoways”` for inclusion of entity *and* time dummies.

```
# estimate a combined time and entity fixed effects regression model
# via lm()
lm(fatal_rate ~ beertax + state + year - 1, data = Fatalities)
fatal_tefe_lm_mod <-
fatal_tefe_lm_mod#>
#> Call:
#> lm(formula = fatal_rate ~ beertax + state + year - 1, data = Fatalities)
#>
#> Coefficients:
#> beertax stateal stateaz statear stateca stateco statect statede
#> -0.63998 3.51137 2.96451 2.87284 2.02618 2.04984 1.67125 2.22711
#> statefl statega stateid stateil statein stateia stateks stateky
#> 3.25132 4.02300 2.86242 1.57287 2.07123 1.98709 2.30707 2.31659
#> statela stateme statemd statema statemi statemn statems statemo
#> 2.67772 2.41713 1.82731 1.42335 2.04488 1.63488 3.49146 2.23598
#> statemt statene statenv statenh statenj statenm stateny statenc
#> 3.17160 2.00846 2.93322 2.27245 1.43016 3.95748 1.34849 3.22630
#> statend stateoh stateok stateor statepa stateri statesc statesd
#> 1.90762 1.85664 2.97776 2.36597 1.76563 1.26964 4.06496 2.52317
#> statetn statetx stateut statevt stateva statewa statewv statewi
#> 2.65670 2.61282 2.36165 2.56100 2.23618 1.87424 2.63364 1.77545
#> statewy year1983 year1984 year1985 year1986 year1987 year1988
#> 3.30791 -0.07990 -0.07242 -0.12398 -0.03786 -0.05090 -0.05180
# via plm()
plm(fatal_rate ~ beertax,
fatal_tefe_mod <-data = Fatalities,
index = c("state", "year"),
model = "within",
effect = "twoways")
coeftest(fatal_tefe_mod, vcov = vcovHC, type = "HC1")
#>
#> t test of coefficients:
#>
#> Estimate Std. Error t value Pr(>|t|)
#> beertax -0.63998 0.35015 -1.8277 0.06865 .
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
```

Before discussing the outcomes we convince ourselves that `state` and `year` are of the class `factor` .

```
# check the class of 'state' and 'year'
class(Fatalities$state)
#> [1] "factor"
class(Fatalities$year)
#> [1] "factor"
```

The `lm()` functions converts factors into dummies automatically. Since we exclude the intercept by adding `-1` to the right-hand side of the regression formula, `lm()` estimates coefficients for \(n + (T-1) = 48 + 6 = 54\) binary variables (6 year dummies and 48 state dummies). Again, `plm()` only reports the estimated coefficient on \(BeerTax\).

The estimated regression function is \[\begin{align} \widehat{FatalityRate} = -\underset{(0.35)}{0.64} \times BeerTax + StateEffects + TimeFixedEffects. \tag{10.8} \end{align}\] The result \(-0.66\) is close to the estimated coefficient for the regression model including only entity fixed effects. Unsurprisingly, the coefficient is less precisely estimated but significantly different from zero at \(10\%\).

In view of (10.7) and (10.8) we conclude that the estimated relationship between traffic fatalities and the real beer tax is not affected by omitted variable bias due to factors that are constant over time.