1
$\begingroup$

[Edited for clarity and detail]

Summary: A random effects model should produced biased estimates for a dynamic panel, but the lmer function of the R lme4 package produces unbiased estimates and I don't know why.

I am comparing the results of the R packages plm and lme4 estimating a dynamic panel of the form

$$y_{it} = \alpha_i + \theta y_{it-1} + x_{it}\beta + \epsilon_{it}$$

with the $\alpha_i$ being unobserved effects. Under the usual assumptions (see Wooldridge 2002 p. 677 for instance), it is well known that this model cannot be estimated by traditional random and fixed effects.

A random effect estimation would consider the unobserved individual parameter $\alpha_i$ as part of the unobserved error term, $\nu_{it} = \alpha_i + \epsilon_{it}$. Because $\alpha_i$ influences $y_{it}$ for every $t$, we have $\text{Cor}(y_{t-1},\nu) \neq 0$ which leads to biased estimates.

A fixed effect estimation can avoid this problem by eliminating the individual effect by, say, differencing. However, it is also biased because the lagged first-difference will end being correlated with the lagged error. (Nickel 1981).

There are several approaches to this problem, but the traditional solutions involve using lags as instruments (Arellano Bond estimator) and there is a rich literature proposing variations of this idea.

But lmer does the job, apparently.

If I have a simulated dataset with two predictors x1 and x2 and the units are indexed by the variable id, this model would be estimated in lme4 as

lmer(y~ lag_y + x1 + x2 + (1|id), data = my_data)

and in plm, an excellent panel data package, as

plm(y ~ lag_y + x1 + x2, index = "id", model = "random", data = my_data)

As one comment pointed out, there is not one way of estimating random effects, but several ("amemiya", "nerlove", etc.). None of these methods recovers the parameters of the dynamic model without bias.

Let's simulate. I will create 100 datasets according to

$$y_{it} = a_i + 0.7 y_{it-1} + 0.5 x_{1,it} - x_{2, it} + e_{it}$$

with $x_1$ and $x_2$ drawn from uniform (-1/2, 1/2). $e$ is a standard normal disturbance. The $a_i$ can drawn be from a normal, but in this example I sampled from {-2, -1.5, ..., 1.5, 2} and I have found that other distributions make no difference. I set $T = 10$ and the number of observed units equal to 50, making a dataset of size $n=500$

The results for 100 simulations with true parameter 0.7 are in the table below. You can find the average across the 100 simulations and the 2.5% and 97.5% percentiles. Notice that one row says "IV" in which I use a random effect model with lagged dependent variables and lagged x as IV.

Method average est. (true = 0.7) 0.025 q 0.975 q
FD fixest 0.612 0.549 0.671
Amemiya plm 0.676 0.614 0.735
Walhus plm 1.001 0 968 1.027
Nerlove plm 0.667 0.606 0.724
Swar plm 1.016 0.969 1.040
lags as "IV" plm 0.662 0.594 0.731
Mixed lme4 0.699 0.632 0.763

While some methods "cover" the true value, the mixed model is the only one that is always centered at the true value.

So the question is, why is the mixed model so good at estimating this model? Some of the other random effects models are clearly producing biased estimates.

Can someone explain to me or guide me to a literature that explains why the mixed model works well in dynamic panels?

Here is reproducible code if you would like to try it:

library(lme4)
library(plm)

gen_one_unit = function(TT, theta = 0.7, beta = c(0.5, -1), s = 1){
# This function generates observations for one "unit" of the panel
  x1 = runif(TT) - .5
  x2 = runif(TT) - .5
  alpha_i = sample(seq(-2, 2, by = .5), size = 1) # arbitrary 
  y = rep(1, TT)                                  # initialize
  for(t in 2:TT){
    y[t] = alpha_i + theta*y[t-1] +
      beta[1]*x1[t] + beta[2]*x2[t]  + rnorm(1, 0, s)
  }
  ind_df = data.frame(alpha_i = rep(alpha_i, TT), x1, x2,
                      y, lagy = c(NA,y[1:(TT-1)]))
  return(ind_df)  
}

H = 50    # number of units
TT = 20   # number o time periods

dyn_linear_list = list()
for(i in 1:H){
  temp_df = gen_one_unit(TT = TT, theta= .5)
  temp_df$id = rep(i, TT)
  dyn_linear_list[[i]] = temp_df
}

dyn_df = do.call(rbind, dyn_linear_list)
dyn_df = dyn_df[!is.na(dyn_df$lagy),]    # get rid of the first obs
reg_plm = plm(y ~ x1 + x2 + lagy,
              model = "random", index = "id",
              # random.method = "amemiya"
              # random.method = "nerlove", etc.
              data = dyn_df)
reg_lme = lmer(y ~ x1 + x2 + lagy + (1|id),
               data = dyn_df)

summary(reg_plm)   # look at the coefficient of lagy
summary(reg_lme)   # look at the coefficient of lagy

References

Nickell, S. (1981). Biases in dynamic models with fixed effects. Econometrica: Journal of the econometric society, 1417-1426.

$\endgroup$
1
  • $\begingroup$ One fact about free software is that, all too commonly, they are not thoroughly tested which means they can be buggy from idiosyncratic coding. Users find the bugs experientially. On the other hand, licensed packages like SPSS or SAS have teams of people responsible for sussing out bugs prior to release, standardizing results and just generally ensuring that they correspond with rigorous expectations. Iow, caveat emptor. $\endgroup$
    – user78229
    Commented Jul 7 at 0:31

1 Answer 1

1
$\begingroup$

The problem seems to be your model specification. If you have a lagged dependent as predictor in your model, it can be problematic to estimate a random effect (or fixed effect) as well. See https://stats.stackexchange.com/a/579031/245825. The fact that the default estimation method for random effect variance in "plm" does not produce a random effect "individual" variance (it is estimated as being zero) may be a symptom of this problem. I tried another estimation method, and this produced almost the same results as lmer:

reg_plm = plm(y ~ x1 + x2 + lagy, data=pd, model="random", random.method="amemiya", index = c("id"))

Also, omitting the lagged dependent leads to highly similar results for plm (with the default random.method) and lmer.

Hopes this helps! Apparently, this was not a problem of free software not being thoroughly tested, but one of searching for the right model and the right estimation procedure, in a situation where several competing methods are (fortunately!) available.

$\endgroup$
5
  • $\begingroup$ Thank you very much! These packages are not just thoroughly tested, they are also open source. Anyone can test it! Once I posted my question, I started looking at all the different plm methods. You are right that some of the methods produce a closer value. But it seems like lme4 nails it and the others are always biased downwards. At the moment of writing, I am going through the derivation of the lme4 estimator to see if I can learn something. I will amend my question this evening to mention the variety of methods. $\endgroup$
    – Hernan
    Commented Jul 9 at 13:02
  • $\begingroup$ The interesting thing is that lme4 produces biased estimates if there is any correlation between the random effects and the predictors, a situation where fixed effects would do just fine. But in the specific case of the lagged dependent variable, it works fine. $\endgroup$
    – Hernan
    Commented Jul 9 at 13:06
  • $\begingroup$ Software being open source is a red herring in this case, but I can see points on both sides too. First, proprietary software often includes code that is visible, as is true of much Stata code for example. Second, testing means different things to different people. In principle absolutely all code in R is visible, but that is more principle than practice; the number of people able and willing to study code in detail is limited. Testing often means reproducing "known" solutions and checking whether difficult or limiting cases are handled reasonably, You can do that for proprietary code too. $\endgroup$
    – Nick Cox
    Commented Jul 9 at 14:08
  • 1
    $\begingroup$ @NickCox Good point about open vs. tested. If you asked me to reproduce results from papers or from textbooks, I would be happier with Stata than with R. $\endgroup$
    – Hernan
    Commented Jul 9 at 21:35
  • 1
    $\begingroup$ Few of us are completely consistent. Stata is my major software which is proprietary but I regard it as a major duty to make public my own Stata programs, which are free and open source except that you need Stata to run them. Most total enthusiasts for open source software that I know regard it as obvious that you must pay companies for operating systems and computing hardware. $\endgroup$
    – Nick Cox
    Commented Jul 9 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.