# Diff-in-Diff special type of OLS?

Is difference-in-differences just a special type of OLS? Can I add fixed effects in my diff-in-diff model?

• stats.stackexchange.com/questions/564/… Commented Nov 14, 2018 at 16:48
• There are actually quite a few counter examples where one can claim to estimate a "difference in differences" without an OLS model. Despite that, the preponderance of DiDs reported in the literature are just OLS (or a suitable GLM for non-continuous outcomes like count or binary). Structural equation models, conditional likelihood models, and some simple applications of the $\delta$-method come to mind. Commented Nov 14, 2018 at 20:58

### Some (perhaps imperfect) definitions

Let's say we have some regression model where $$\theta$$ denotes a parameter of interest and $$(x_i, y_i)$$ denotes the $$i$$th observation:

$$y_i = f(\theta, x_i) + \epsilon_i$$

(Note: part of what makes this a regression problem is that $$y_i \in \mathbb{R}$$ is a continuous variable. If $$y_i$$ were either "dog" or "cat" it would be a classification problem.)

A method to estimate $$\theta$$ is ordinary least squares, that is, you choose $$\theta$$ to minimize the sum of squared error:

$$$$\begin{array}{*2{>{\displaystyle}r}} \mbox{minimize (over \theta)} & \sum_{i=1}^n \epsilon_i^2 \\ \mbox{subject to} & y_i = f(\theta, x_i) + \epsilon_i \end{array}$$$$

If $$f(\theta)$$ is a linear function, then the model is a linear regression model:

$$y_i = \theta \cdot x_i + \epsilon_i$$

Difference in difference refers to an empirical strategy or model where some treatment effect is estimated by comparing changes in the treatment group over time to changes in the control group over time. The model is typically a linear regression model estimated using ordinary least squares.

### Simple example of difference in difference model

Let's assume say everyone in group $$G$$ receives treatment at time $$t_e$$.

• Let $$\mathbf{1}_A(X)$$ denote the indicator function where $$\mathbf{1}_A(x) = \left\{ \begin{array}{cl} 1& \text{if } x \in A \\ 0 & \text{if } x \notin A \end{array} \right.$$.

• Let $$T = \{t : t > t_e\}$$ denote the time period after the treatment event.

• $$\mathbf{1}_T(t) = 1$$ if $$t > t_e$$
• $$\mathbf{1}_G(i) = 1$$ if agent $$i$$ belongs to the group $$G$$ that receives treatment.
• $$\mathbf{1}_T(t)\mathbf{1}_G(i) = 1$$ if both $$t > t_{e}$$ and $$i \in G$$.

We could write a linear regression model:

$$y_{it} = b_0 + b_1 \mathbf{1}_T(t) + b_2 \mathbf{1}_{G}(i) + b_3 \mathbf{1}_T(t)\mathbf{1}_{G}(i) + \epsilon_{it}$$

The difference in difference term we care about would be $$b_3$$. It is how much the treatment group changes after the treatment event compared to how much the control group changes after the treatment event.

A key requirement for difference and difference to consistently estimate an effect is parallel trends. The level of $$y_{it}$$ can be different for the treatment and control but they must move in parallel.

You can add controls to difference in difference models.

-- Update 2019 -- What you can and can't do with control variables deserves a longer discussion. This answer gets at some of the issues. Keep in mind that the key assumption of difference in difference estimation is that treatment and control would have followed parallel trends had treatment not occurred.

• +1,, good answer,,, can you please give a reference for this? Commented Aug 29, 2019 at 16:34