最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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)
发布评论

评论列表(0)

  1. 暂无评论