r - Event Study Design using OLS yields estimates despite no variance in outcome variable - Stack Overflow

I am running an event study design and get some unexpected behavior using OLS. One of my outcome variab

I am running an event study design and get some unexpected behavior using OLS. One of my outcome variables is by definition zero before the treatment, i.e., whenever event time is weakly smaller than 0. I am convinced OLS shouldn't return estimates if there is no variance in the outcome (it's always zero for event_time <= 0). Below is a reproducible example. I get the expected behavior if I use fixed effects in a Poisson regression (which I intend to use for reasons unrelated to this issue), but not using fixed effects in feols.

Am I wrong, or is this a bug? Could it be some edge case I am unaware of? I am grateful for any pointers.

library(fixest)
library(dplyr)

set.seed(123)

n_units <- 500
n_periods <- 10 
n_rows <- n_units * n_periods

panel <- expand.grid(unit_id = as.character(1:n_units),
                     event_time = -4:5) %>%
  arrange(unit_id, event_time) %>%
  mutate(treated = ifelse(runif(n_rows) > 0.5, 1, 0),  
         outcome = ifelse(event_time <= 0, 0, rpois(n_rows, lambda = 1)),  
         time = sample(1:1000, n_rows, replace = TRUE),
         cluster_id = sample(1:100, n_rows, replace = TRUE))

# outcome is always 0 for event_time <= 0
panel %>% group_by(event_time <= 0) %>% distinct(outcome)

model_1 <- lm(outcome ~ i(event_time, treated, ref = 0),
              data = panel)

model_2 <- feols(outcome ~ i(event_time, treated, ref = 0) |
                   unit_id + event_time + time,
                 data = panel)

model_3 <- feglm(outcome ~ i(event_time, treated, ref = 0) |
                   unit_id + event_time + time,
                  family = "poisson",
                 data = panel)

summary(model_1)
etable(model_2, model_3)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744410288a4572839.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信