R语言 fixest::sunab(),包含每日水平数据,每月治疗

yrdbyhpb  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(87)

我想在日常水平上使用面板估计fixest::sunab,但每个月都有点估计。目前看起来这是不可能的,但这里有一个玩具数据集:

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

我正在努力做到这一点,而不聚集到每月的水平。到目前为止,简单的fixest::feols(yvar ~ sunab(date, treatment_dates) | district + date, data = final_panel)有几个缺点:
1.它丢弃NA(从未处理组)。我将从未治疗的组重新编码为“2001-01-01”,然后使用ref.c参数。

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

1.这在技术上是可行的,尽管这不是我想要的:我想点估计被装箱的一个月,或其他一些金额。我已经研究了bin参数,尽管我不确定在这种情况下如何工作。
如前所述,如果不加总,这可能是不可能的,但我问这个问题是因为我试图保持日期固定的效果。

aiazj4mn

aiazj4mn1#

你应该在面板中将从未治疗过的单位编码为在某个日期> max(date)治疗过(比如,它们将在2040年治疗),那么就不会有NA下降。

相关问题