# Multi-level model with varying intercept vs. fixed effect regression

I'm working through Gelman and Hill, Data Analysis and Regression using Multilevel/Hierarchical Models (2007), using the arm package, and trying to relate multilevel models to the econometric framework I'm more familiar with. I expected a multilevel model with a non-varying slope coefficient and a varying intercept coefficient to provide identical results to a fixed effect regression with no constant.

I expected the following R and Stata code to produce the same results. They do not - can you tell me why?

R code:

M1 <- lmer(y ~ x1 + x2 + (1 | county))


Stata code:

reg y x1 x2 i.county, noconstant


The coefficients produced by these two approaches are quite different.

The Stata code regresses y on x1, x2 and K additional indicator variables for each county. What is R doing that is different? Is there an OLS regression analog?

• Please supply the full Gelman and King reference. – Nick Cox Jan 15 '14 at 14:26
• Gelman and Hill, is what I meant to say. – pnj Jan 15 '14 at 15:23

The key difference is the lmer() is a random effects model and xtreg with the fe option is a fixed effects model. A random effects model forces the random constant to be independent of x1 and x2 while a fixed effects model allows for correlations.

The effects for individual counties you get with your reg command are not necessary. You can have Stata produce a fixed effects models with only the constant and the effects of x1 and x2 by typing in Stata:

xtset county
xtreg y x1 x2, fe


This fixed effects model is exactly the same as the one you estimated with reg. You can see that by running this code:

// here I import the data you linked to
import delimited C:\temp\test.csv

// fixed effects regression using xtreg
xtset county
xtreg y x1 x2, fe

// fixed effects regression using reg
reg y x1 x2 ibn.county, hascons


The coefficients and standard errors of x1 and x2 of these two models are exactly the same.

• Your code produces a third set of coefficients, different from both the R and Stata code I listed above. Can you explain or link to an explanation? Here's the data I use: link – pnj Jan 15 '14 at 19:03
• I edited the answer to respond. In short, I did not give you a third set of estimates, just a more efficient way of getting the estimates of the fixed effects regression. – Maarten Buis Jan 16 '14 at 9:16
• Ok, so I understand that xtreg, fe is omitting a county, which explains a difference so now the two Stata fragments produce the same result. But my original question is still not answered - why does the R lmer() function produce different results? How is a multilevel model with varying intercept and non-varying slope different from the fixed effect model as implemented in Stata? – pnj Jan 16 '14 at 13:38
• No, xtreg, fe does not omit a country. I explained the difference between fixed and random effects above, so I don't understand what you do not understand. – Maarten Buis Jan 16 '14 at 13:41
• Maybe you did not realize that lmer() is a random effects model? – Maarten Buis Jan 16 '14 at 13:42

The key difference is that in a fixed effects model estimates each higher level unit is treated as a separate entity - in effect each estimate is a mean. In a random effects model the allowed to vary differences are assumed to come from a distribution typically a Normal one around an overall mean . If each higher level unit is based on lot of information - that is many cases the fixed and random estimates will be very similar. But if there is little information the random effects estimate will be shrunk towards the overall mean. This is known as precision-weighted estimation and is a very useful property as strength is borrowed for a particulate estimate from all estimates, and mean square error can be reduced.

This paper does the comparison algebraically and empirically, and this paper does argues the case for the usefulness of random effects model. This paper has some simulations showing effects.