# Applying Fixed Effects in a Difference-In-Differences Estimation using Least Square Dummy Variable Approach in R

I am trying to do a difference-In-differences (DiD) regression with fixed effects. The regression is meant to estimate the impact of participating in a televised Sports Event on the Social Media Follower Count of the participating teams, compared to other teams that did not participate.

My data looks like this:

The dependent variable is the Rate_Percent, which is the growth rate of Facebook-Likes, which is calculated as follows:

Dataset_FB <- Dataset_FB %>% group_by(ID) %>%
mutate(Diff_Growth = FBLikes - lag(FBLikes),
Rate_Percent = Diff_Growth / lag(FBLikes) * 100)


Teilnahme is a dummy variable to tell the participants from the non-participants, and Hauptrunde is a dummy variable to indicate the time frame of the treatment (0 before the treatment, 1 after the treatment). I am trying to include the ID, Uhrzeit and Spieltag as fixed effects to control for club- and time- differences.

My regression looks like this:

reg <- lm (Rate_Percent ~ Teilnahme + Hauptrunde + Teilnahme*Hauptrunde + factor(ID) + factor(Uhrzeit) + factor(Spieltag), data=Dataset_FB)


The factor(ID) seems to mess things up. It is supposed to be a fixed effect dummy for each $$n$$.

Now, my questions are as follows:

1. The summary looks far from correct, but I can't find my mistakes, what did I do wrong?
2. Is this the correct way to use fixed effects?
3. I know "Coefficients: (6 not defined because of singularities)" indicates a strong correlation between my independent variables. But when I don't use the factor(ID) in the regression, the coefficients are there.

The summary looks like this:

lm(formula = Rate_Percent ~ Teilnahme + Hauptrunde + Teilnahme *
Hauptrunde + factor(ID) + factor(Uhrzeit) + factor(Spieltag),
data = Dataset_FB)

Residuals:
Min      1Q  Median      3Q     Max
-0.2834 -0.0343 -0.0111  0.0092  4.9302

Coefficients: (6 not defined because of singularities)
Estimate Std. Error t value Pr(>|t|)
(Intercept)           0.0266970  0.0125098   2.134  0.03288 *
Teilnahme             0.0020571  0.1662742   0.012  0.99013
Hauptrunde           -0.0158433  0.0060631  -2.613  0.00900 **
factor(ID)8          -0.0344717  0.0171467  -2.010  0.04443 *
factor(ID)25         -0.0155100  0.1662745  -0.093  0.92568
factor(ID)56          0.0122209  0.0171467   0.713  0.47604
factor(ID)69         -0.0093248  0.1662745  -0.056  0.95528
factor(ID)90         -0.0037743  0.0171467  -0.220  0.82578
factor(ID)93          0.0948638  0.0171467   5.532 3.29e-08 ***
factor(ID)103         0.0117689  0.0171467   0.686  0.49251
factor(ID)115         0.0479442  0.0171467   2.796  0.00519 **
factor(ID)166        -0.0129542  0.0171467  -0.755  0.44998
factor(ID)364        -0.0112018  0.0171467  -0.653  0.51359
factor(ID)373        -0.0111296  0.0171467  -0.649  0.51631
factor(ID)490        -0.0231408  0.0171467  -1.350  0.17720
factor(ID)752        -0.0064241  0.0171467  -0.375  0.70793
factor(ID)907         0.1333400  0.0171467   7.776 8.75e-15 ***
factor(ID)951         0.0087327  0.0171467   0.509  0.61057
factor(ID)996        -0.0105943  0.0171467  -0.618  0.53669
factor(ID)1238        0.0076285  0.0171467   0.445  0.65641
factor(ID)1315        0.0304732  0.1662745   0.183  0.85459
factor(ID)1316        0.1290605  0.0171467   7.527 5.98e-14 ***
factor(ID)1400        0.0038137  0.0171467   0.222  0.82400
factor(ID)1401       -0.0135700  0.0171467  -0.791  0.42874
factor(ID)1712       -0.0001285  0.0171467  -0.007  0.99402
factor(ID)3417        0.0053766  0.0171467   0.314  0.75386
factor(ID)5646        0.0052521  0.0171467   0.306  0.75939
factor(ID)6273       -0.0134096  0.0171467  -0.782  0.43422
factor(ID)7679       -0.0104365  0.0171467  -0.609  0.54277
factor(ID)9029               NA         NA      NA       NA
factor(ID)10213      -0.0441121  0.0171467  -2.573  0.01012 *
factor(ID)26957      -0.0287541  0.0171700  -1.675  0.09405 .
factor(ID)29988       0.1015109  0.1662745   0.611  0.54155
factor(ID)40373       0.0203831  0.0171467   1.189  0.23459
factor(Uhrzeit)1530   0.0206731  0.1653880   0.125  0.90053
factor(Uhrzeit)1830          NA         NA      NA       NA
factor(Uhrzeit)2045          NA         NA      NA       NA
factor(Spieltag)NA           NA         NA      NA       NA
factor(Spieltag)Sa           NA         NA      NA       NA
factor(Spieltag)So           NA         NA      NA       NA
Teilnahme:Hauptrunde  0.0053874  0.0085752   0.628  0.52987
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1649 on 5885 degrees of freedom
(32 observations deleted due to missingness)
Multiple R-squared:  0.07278,   Adjusted R-squared:  0.06742
F-statistic: 13.59 on 34 and 5885 DF,  p-value: < 2.2e-16

• Welcome. Your ID's represent your participants, correct? And if so, are they are nested within certain clubs (e.g., Uhrzeit, Spieltag, etc.)? I'm just trying to wrap my head around the different variables. Also, does a participant always stay within their particular club over time? Some further clarification will be helpful. – Thomas Bilach Apr 10 at 17:45
• Hello Thomas and thank you for you comment. Yes, the ID is representing the participants. The clubs themselves are the participants and that does not change over time. I am not sure what it means if the IDs are 'nested' within certain clubs. The 'original' variable of Uhrzeit (time of participation in the Event) for example has three levels(?), and each club (ID) has participated at only one time of the three. So I assume the factor(Uhrzeit) command creates three dummy variables, one for each time. Did that help you? I'm having a hard time wrapping my head around all this myself. – Superjibombu Apr 10 at 18:49
• Thank you for the clarification. Also, do treated participants enter into the treatment at the same time? If so, I assume the "post-treatment" variable switches from 0 to 1 during the same time periods for all individuals. Correct? – Thomas Bilach Apr 10 at 19:47
• Yes, the time span of the treatment is the same for all participants, meaning the dummy for post-treatment (in my case, Hauptrunde) switches to 1 during that time. – Superjibombu Apr 10 at 20:12

The summary looks far from correct, but I can't find my mistakes, what did I do wrong?

It doesn't appear you did anything wrong. Software simply dropped the redundant regressors. In your setting, it shouldn't affect the difference-in-differences coefficient.

First, the panel unit is the individual. And the individual is observed over time. According to the model summary, the treatment dummy (i.e., Teilnahme) is collinear with the individual fixed effects. A person's membership to the "treatment group" or the "control group" is fixed over time. The individual fixed effects already account for this.

The variables that R drops is merely an artifact of your ordering scheme. In the model formula, the individual fixed effects are specified last. R cannot estimable all individual-specific intercepts if they are preceded by a time-constant treatment indicator; one additional individual effect must be dropped as a compromise. Conversely, if the individual fixed effects were specified first, then they would absorb Teilnahme. Try out the latter approach; it will completely absorb any dummy representing group membership. Note: neither situation affects the estimate on your interaction term.

The example code below shows three ways of estimating your equation. Your interaction term should remain unaffected by these alternative specifications.

## 1 - Unit Fixed Effects Last

# One individual dummy variable must be dropped
# This is in addition to the one software automatically drops to avoid the dummy variable trap

lm(Rate_Percent ~ Teilnahme + Hauptrunde + Teilnahme * Hauptrunde + factor(ID), data = Dataset_FB)

## 2 - Unit Fixed Effects First

# The treatment dummy is absorbed entirely
# Membership to the treatment group is time-invariant

lm(Rate_Percent ~ factor(ID) + Teilnahme + Hauptrunde + Teilnahme * Hauptrunde, data = Dataset_FB)

## 3 - No Singularities

# If you want cleaner output, then instantiate the interaction term manually
# The function I() modifies the variables as is
# It doesn't affect the original data frame

lm(Rate_Percent ~ I(Teilnahme * Hauptrunde) + Hauptrunde + factor(ID), data = Dataset_FB)


Even though collinearity is present, it shouldn't affect your interaction term.

To be clear, you're estimating the classical difference-in-differences equation where some intervention impacts all treated entities at the same time. Your code may be simplified as following:

lm(Rate_Percent ~ Teilnahme * Hauptrunde, data = Dataset_FB)


The constituent terms will be estimated without any additional work on your part. The code is much more concise and should produce equivalent results.

Is this the correct way to use fixed effects?

Yes.

Technically, a difference-in-differences model is a "within" model. It is perfectly permissible to estimate it using unit and/or time fixed effects. For reporting purposes, I would omit the individual fixed effects entirely; they're nuisance. The interaction term is what counts.

I know "Coefficients: (6 not defined because of singularities)" indicates a strong correlation between my independent variables. But when I don't use the factor(ID) in the regression, the coefficients are there.

What you have is perfect collinearity. But for this application, it isn't a problem. As for your other dummies (e.g., Spieltag), it appears the "participation time" is a fixed attribute of each individual. It doesn't vary over time! The individual fixed effects already account for this. You can safely drop these from your analysis.

As a final word, it is often good practice to assign variable names that are easy to identify just by looking at your equation. For example, I recommend renaming Hauptrunde to something like post or after. It may seem unnecessary, but it's often helpful to others reviewing your post.

• Thank you very much for your answer (and your patience with my post). It helped me understand my own model a lot better. Also, thank you for the formatting. You were a great help! – Superjibombu Apr 11 at 9:20
• No problem! If I cleared things up, then give it the check. – Thomas Bilach Apr 11 at 16:07
• @Superjibombu Be careful when estimating the third equation. For instance, sometimes people see I(Treatment * Post) and they assume they can omit the constituent parts of the product term. You cannot do this. All variables must be present. The only reason I dropped the treatment dummy is because the relevant information is captured by the unit fixed effects. – Thomas Bilach Apr 11 at 18:15
• Thanks again for the further clarification. My questions are answered, good thing you pointed out the check button. – Superjibombu Apr 11 at 22:56