# Simple example of a Fixed vs. Random effects model

Wikipedia's page on Random effects models gives a simple illustrative example of a random effect occurring in a panel analysis amongst pupils' performance on schools. Wikipedia's page on Fixed effects models lacks such an example.

So, in order to meet the persisting need* for clear explanations between Fixed and Random effects models, I think it would be of added-value to alter the pupils' performance example to exemplify a fixed effect in such a panel analysis. Serving both as a contribution to Fixed effects' Wikipedia page and my understanding of the two models, I propose the following tweaked example:

Suppose $$m$$ large elementary schools are chosen randomly from among thousands in a large country. Suppose also that $$n$$ pupils of the same age are chosen randomly at each selected school. Their scores on a standard aptitude test are ascertained. Let $$Y_{i,j}$$ be the score of the $$j$$th pupil at the $$i$$th school. If one considers scores $$Y_{i,j}$$ to be subject to the non-random assignment of students to schools, a Fixed effects model can be used to difference out unobserved heterogeneity. A simple way to model the relationships of these quantities is $$Y_{i,j} = \mu + U_i + W_{i,j},$$ where $$\mu$$ is the average test score for the entire population.

Can $$U_i$$ in this context be called the school-specific fixed effect, i.e. it measures the difference between the average score at school $$i$$ and the average score in the entire country? The same question for the term $$W_{i,j}$$, is it the individual-specific fixed effect, i.e., it's the deviation of the $$j$$-th pupil’s score from the average for the $$i$$-th school?

Please let me know if you have any suggestions.

*amongst others: this, this and this posts

Inverting your subscripts will ease the interpretation. I would consider the $$i$$-th student nested within the $$j$$-th school. Reproducing (and tweaking) your model results in the following

$$y_{ij} = \mathbf{x}_{ij}^{'} \boldsymbol\beta + \alpha_j + \epsilon_{ij},$$

where $$\alpha_{j}$$ is now the "effect" for school $$j$$. In addition to containing all covariates, $$\mathbf{x}_{ij}$$ also contains the intercept $$\mu$$.

Can [$$\alpha_{j}$$] in this context be called the school-specific fixed effect?

Yes. However, please note the difference in notation I have proposed.

[I]t measures the difference between the average score at school $$j$$ and the average score in the entire country?

To address the second component of your question, it is important to review the mechanics of fixed effects estimation. In a fixed effects model, the school effects are treated as a nuisance. There are two alternative approaches to estimation: one where we 'difference out' (i.e., subtract out) the school effect and another where we incorporate dummy variables for schools. Differencing results in the following,

$$y_{ij} - \bar{y}_{j} = (\mathbf{x}_{ij} - \mathbf{\bar{x}}_{j})^{'} \boldsymbol\beta + \epsilon_{ij} - \bar{\epsilon}_j$$

where we subtract off the within-school means. In other words, you decrement the student mean within school $$j$$ from each realization of $$y_{ij}$$ and $$x_{ij}$$. Note, the model no longer contains the school effect $$\alpha_{j}$$; it was removed via the within-transformation. In panel data contexts with multiple $$t$$ time periods (Level 1) embedded (nested) within $$i$$ individuals/entities (Level 2), then this transformation is referred to as time-demeaning. Interestingly, this discussion paper refers to the 'sweeping out' of $$\alpha_{j}$$ in the foregoing model as a pupil-demeaned model. Most of the work presented in that paper was later published in 2015 in Education Economics. I highly encourage you to review this paper.

The next formulation includes the school effects as covariates,

$$y_{ij} = \mathbf{x}_{ij}^{'} \boldsymbol\beta + \sum_{j=1}^{J} \alpha_{j}S_{j} + \epsilon_{ij},$$

where $$S_{j}$$ denotes dummies for school membership. $$\alpha_{j}$$ now represents the $$j$$-th additive school effect. For identification purposes, one school must be constrained to equal 0. Incorporating a full series of school dummies is algebraically equivalent to estimation in deviations from means. Parameterizing the model in this way shows how the coefficients on these dummies represent school-specific intercepts. Each school now has its own unique, fixed intercept.

The same question for the term [$$\epsilon_{ij}$$], is it the individual-specific fixed effect?

No. This is not considered a student-specific effect. This is your student-level residual.

I also want to add some final thoughts. At times you refer to "sample" and "population" as interchangeable. In your example, you indicate that the "group" effect is part of a larger, unobserved population. In other words, your sample of $$j$$ schools is randomly culled from the full population of elementary schools—and you intend to draw inferences about the population using this random subset of schools. If you are interested in the educational institutions of the entire country, then you might want to treat $$\alpha_{j}$$ as random.