Why is `fixest` not allowing for lagged variables?

59 views Asked by At

I am dealing with fixed-effects regressions in R using the fixest package. Let's suppose I want to estimate something super simple as

$$

Y_{i, t} = \alpha + \beta X_{i, t-1} + u_{i, t}

$$

So I want to regress a dependent variable on the lagged value of a regressor. The code I have is the following:

library(tidyverse)
library(fixest)
library(here)

my_data <- read_csv("test_data.csv")
mod1 <- feols(short_disagreement ~ l(leverage, 1), 
             my_data, 
             panel.id = c("gvkey", "month"))

mod2 <- feols(short_disagreement ~ lagged_leverage, 
              my_data |> group_by(gvkey) |> mutate(lagged_leverage = lag(leverage, 1)),
              panel.id = c("gvkey", "month"))

where gvkey is an id for each individual of this panel and month is a date variable.

Although I can estimate mod2 with no problems, fixest will throw an error for mod1:

Error in feols(short_disagreement ~ l(leverage, 1), my_data, panel.id = c("gvkey",  : 
  All observations contain NAs. Estimation cannot be done. (Breakup: RHS: 39,803.)

Data is here: https://drive.google.com/file/d/1oupZX8iQNQv6_q-2wYlCV-Nax40jAByk/view?usp=sharing

0

There are 0 answers