lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
361 stars 59 forks source link

Package won't allow for lagged variables #450

Open rgriva opened 8 months ago

rgriva commented 8 months ago

I am trying to estimate a simple linear model in a panel setting. I would like to use the l() function provided by fixest. Here is the example:

library(tidyverse)
library(fixest)

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"))

The variables gvkey and month are track individuals and time in this data. I can estimate mod2 but I can't estimate mod1. It will throw the following error:

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.)

Here is the data in csv format: https://drive.google.com/file/d/1oupZX8iQNQv6_q-2wYlCV-Nax40jAByk/view?usp=sharing

Any ideas on what's happening?