I would like to estimate fixest::sunab
using a panel at the daily-level, but with point estimates binned for every month. It does not look like this is possible at the moment, but here is a toy data set:
library(tidyverse)
library(fixest)
## creating a panel
panel_dates <- seq(as_date("2016-01-01"), as_date("2022-12-31") , by= "day") %>%
as_tibble() %>%
rename(date = value)
districts <- c(1:20, 22, 24, 25) %>%
as_tibble() %>%
rename(district = value) %>%
filter(district != 13)
panel_dates <- panel_dates %>%
cross_join(districts)
treatments <- tibble("district" = c(1:20, 22, 24, 25),"treatment_dates" = as_date(c("2018-05-16",
"2018-01-29",
"2018-03-16",
"2017-01-13",
"2017-10-12",
"2018-03-28",
rep(NA, 17))))
## panel for analysis (fake data)
final_panel <- panel_dates %>%
left_join(treatments, join_by(district == district)) %>%
mutate(yvar = rnorm(n = row_number()))
I am trying to accomplish this without aggregating to the monthly level. So far, a simple fixest::feols(yvar ~ sunab(date, treatment_dates) | district + date, data = final_panel)
has several drawbacks:
- It drops the NAs (the never treated group). I recoded the never treated group to be "2001-01-01" and then used the
ref.c
argument.
## creating a never-treated groupw ith pseudo-treatment in 2001 01 01
final_panel <- final_panel %>%
mutate(treatment_dates = if_else(is.na(treatment_dates), as_date("2001-01-01"),
treatment_dates))
## estimating the model with 2001-01-01 as the reference period
## WARNING BEFORE RUNNING: TAKES VERY LONG TIME TO EXECUTE - LIKELY BECAUSE OF THE MANY ESTIMATIONS NEEDED AT THE DAILY LEVEL
fixest::feols(yvar ~ sunab(period = date,cohort = treatment_dates, ref.c = as_date("2001-01-01")) |
district + date, data = final_panel)
- This technically works, although it is not what I am after: I would like the point-estimates to be binned by the month, or some other amount. I have looked into the
bin
argument, although I am unsure how this would work in such a case.
As stated earlier in the post, this may be impossible without aggregating up, but I am asking this as I am trying to keep the date fixed effects.