Comparing Fixed Effects and Multilevel Models Using World Bank Data
Author
Andrew Grogan-Kaylor
Published
October 25, 2025
1 Background
Multilevel models for longitudinal data, and fixed effects regression provide two alternative methods for analyzing longitudinal data.
Briefly…
Here, level 2 units are countries. Level 1 is a country-year. Level 2 is the country.
Multilevel models use both within level 2 unit and between level 2 unit variation, and provide statistical control for observed variables that are included in the model.
Fixed effect regressions use only within level 2 unit variation. As a consequence, fixed effects regression is unable to provide parameter estimates for time invariant variables, even when they are included in the statistical model. Fixed effects regressions provide statistical controls for all time invariant variables, whether observed or unobserved.
Here \(\beta_0\) is the intercept, \(\beta_1\) is a slope, \(u_{0i}\) is a country specific intercept, and \(e_{it}\) is a measurement specific error term.
Key Idea
In the multilevel model, the \(u_{0i}\) are considered to have a distribution, with a mean of 0 and a standard deviation \(\sigma_{u0}\). In the fixed effects regression model, the \(u_{0i}\) are considered to be fixed, and directly estimable, although in practice, estimates for each of the \(u_{0i}\) are usually not provided.
use"WorldBankData.dta", cleardescribe life_expectancy year Gini GDP undernourishment region
Variable Storage Display Value
name type format label Variable label
-------------------------------------------------------------------------------------
life_expectancy double %10.0g Life expectancy at birth, total (years)
year long %12.0g
Gini double %10.0g Gini index (World Bank estimate)
GDP double %10.0g GDP per capita (current US$)
undernourishm~t double %10.0g Prevalence of undernourishment (% of
population)
region str26 %-9s
4 Process The Data
dropif region == "Aggregates"// drop rows of data representing Aggregatesencode region, generate(regionNUMERIC) // numeric version of region
(1,927 observations deleted)
5 Graph
histogram life_expectancy, scheme(michigan) title("Life Expectancy at Birth") fcolor(%50)graphexporthistogram.png, replace
histogram of life expectancy
6 Multilevel Model (mixed y x || id:)
MLM
The model uses within and between level 2 unit variation. Estimates are provided for all variables. The model only controls for variables that are included in the model.
mixed life_expectancy year Gini GDP undernourishment i.regionNUMERIC || country:eststore MLM
Performing EM optimization ...
Performing gradient-based optimization:
Iteration 0: Log likelihood = -1941.3024
Iteration 1: Log likelihood = -1941.3024
Computing standard errors ...
Mixed-effects ML regression Number of obs = 1,226
Group variable: country Number of groups = 140
Obs per group:
min = 1
avg = 8.8
max = 19
Wald chi2(10) = 3393.70
Log likelihood = -1941.3024 Prob > chi2 = 0.0000
------------------------------------------------------------------------------------
life_expectancy | Coefficient Std. err. z P>|z| [95% conf. interval]
-------------------+----------------------------------------------------------------
year | .2681652 .0070473 38.05 0.000 .2543527 .2819777
Gini | -.0051665 .012107 -0.43 0.670 -.0288958 .0185627
GDP | -2.70e-06 6.03e-06 -0.45 0.655 -.0000145 9.13e-06
undernourishment | -.0712303 .0099802 -7.14 0.000 -.0907911 -.0516696
|
regionNUMERIC |
Europe & Centra.. | 5.023854 1.293808 3.88 0.000 2.488037 7.559671
Latin America &.. | 2.760078 1.51168 1.83 0.068 -.2027596 5.722916
Middle East & N.. | 2.318189 1.695885 1.37 0.172 -1.005684 5.642062
North America | 8.060808 3.494181 2.31 0.021 1.21234 14.90928
South Asia | -2.013143 2.365438 -0.85 0.395 -6.649317 2.62303
Sub-Saharan Afr.. | -12.27801 1.343098 -9.14 0.000 -14.91043 -9.645584
|
_cons | -467.0279 14.36493 -32.51 0.000 -495.1826 -438.8731
------------------------------------------------------------------------------------
------------------------------------------------------------------------------
Random-effects parameters | Estimate Std. err. [95% conf. interval]
-----------------------------+------------------------------------------------
country: Identity |
var(_cons) | 21.89217 2.712469 17.17211 27.90961
-----------------------------+------------------------------------------------
var(Residual) | .7722833 .0332602 .70977 .8403025
------------------------------------------------------------------------------
LR test vs. linear model: chibar2(01) = 2403.93 Prob >= chibar2 = 0.0000
7 Fixed Effects Model (xtreg y x, i(id) fe)
FE
The model uses only within level 2 unit variation. Estimates are only provided for within level 2 unit change over time. The model controls for all time invariant variables whether observed or unobserved.
xtreg life_expectancy year Gini GDP undernourishment i.regionNUMERIC, i(country) feeststore FE
note: 2.regionNUMERIC omitted because of collinearity.
note: 3.regionNUMERIC omitted because of collinearity.
note: 4.regionNUMERIC omitted because of collinearity.
note: 5.regionNUMERIC omitted because of collinearity.
note: 6.regionNUMERIC omitted because of collinearity.
note: 7.regionNUMERIC omitted because of collinearity.
Fixed-effects (within) regression Number of obs = 1,226
Group variable: country Number of groups = 140
R-squared: Obs per group:
Within = 0.7362 min = 1
Between = 0.2773 avg = 8.8
Overall = 0.1152 max = 19
F(4, 1082) = 754.84
corr(u_i, Xb) = 0.1247 Prob > F = 0.0000
------------------------------------------------------------------------------------
life_expectancy | Coefficient Std. err. t P>|t| [95% conf. interval]
-------------------+----------------------------------------------------------------
year | .2765033 .0071426 38.71 0.000 .2624883 .2905183
Gini | -.0020466 .0122625 -0.17 0.867 -.0261077 .0220144
GDP | -.0000126 6.21e-06 -2.04 0.042 -.0000248 -4.63e-07
undernourishment | -.0597049 .0102307 -5.84 0.000 -.0797792 -.0396306
|
regionNUMERIC |
Europe & Centra.. | 0 (omitted)
Latin America &.. | 0 (omitted)
Middle East & N.. | 0 (omitted)
North America | 0 (omitted)
South Asia | 0 (omitted)
Sub-Saharan Afr.. | 0 (omitted)
|
_cons | -480.9276 14.48041 -33.21 0.000 -509.3405 -452.5148
-------------------+----------------------------------------------------------------
sigma_u | 8.6615053
sigma_e | .87884005
rho | .98980975 (fraction of variance due to u_i)
------------------------------------------------------------------------------------
F test that all u_i=0: F(139, 1082) = 196.61 Prob > F = 0.0000
8 Compare The Two Sets of Estimates (estimates table)
Omitted Category
NB that the omitted category for region is “East Asia & Pacific”.
The multilevel model controls for variables that are included in the model.
The fixed effects model controls for variables that are included in the model, as well as all time invariant characteristics of countries.
The multilevel model uses both within and between country variation; the fixed effects model uses only within country variation.
The fixed effects model is unable to provide information on time invariant characteristics of countries (AKA Level 2 variables) even if they are included in the model. All time invariant characteristics of countries (AKA Level 2 variables) are excluded from the estimates.
As a result of (3), the fixed effects model is less statistically efficient than the multilevel model. Coefficients in the fixed effects model are generally smaller than coefficients in the multilevel model. (Often, though not in this example, coefficients that were significant in the multilevel model are not significant in the fixed effects model). Sometimes this is a result of the increased statistical control afforded by the fixed effects regression; sometimes this is a result of the decreased statistical efficiency of the fixed effects regression.
Multilevel models rely on the assumption that the random effects (\(u\)’s) are uncorrelated with the regressors (\(x\)’s). Fixed effects regression models do not rely on this assumption.
Random slopes are a part of the multilevel modeling framework allowing for exploration of the diversity of regression slopes across individuals and contexts. Random slopes are not part of the fixed effects regression framework.
esttable MLM FE, star equations(1) b(%9.3f) stats(N r2_a)