chaisemartinPackages / did_multiplegt_dyn

|| Stata | R || Estimation of event-study Difference-in-Difference (DID) estimators in designs with multiple groups and periods, and with a potentially non-binary treatment that may increase or decrease multiple times.
38 stars 8 forks source link

by and by_path setting #64

Closed lbiagini75 closed 4 months ago

lbiagini75 commented 4 months ago

I try to use this setting with a binary variable "sel_1" (numeric no factor) in R but the code report this error

Error in if (!did_multiplegt_dyn_by_check(df, group, by)) { : 
  missing value where TRUE/FALSE needed
chaisemartinPackages commented 4 months ago

Hi Luigi, This is Diego from Clément de Chaisemartin's RA Team. Thanks for your interest in DIDmultiplegtDYN! This error message could only appear if one of the arguments from that line is missing. To this end, could you share with me the code that you use to call the command where this bug happens? It would be first-best if you could also share a reduced version of your data where this bug still occurs. In this way, I would be able to debug with more precision. In any case, you could send you code and/or data to: chaisemartin.packages@gmail.com. Let me know if this works for you. Best, Diego

lbiagini75 commented 4 months ago

Hi Diego, Thank you for your prompt response and for your assistance. As requested, I am sharing the code snippet where the error occurs:

mod_dCDH24=did_multiplegt_dyn(
  df=data_did,
  outcome='Y',
  group='ID',
  time='Year',
  treatment=D',
  effects = 6,
  normalized = TRUE,
  normalized_weights = TRUE,
  placebo = 3,
  cluster = c('ID'),
 by = c('sel_1'), #Estimating heterogeneous effects:
  only_never_switchers = T,
  ci_level = 95,
  graph_off = FALSE,
  dont_drop_larger_lower = T,
  drop_if_d_miss_before_first_switch = T
)

This should help in debugging the problem more precisely. Please let me know if you need any further information or clarification. Best regards, Luigi

DiegoCiccia commented 4 months ago

Hi Luigi, It seems that the program fails because the return from the inner program did_multiplegt_dyn_by_check is missing, instead of a logical value. This may happen because the group-level average of by var returns a missing, for some reason related to your data. To circumvent this, I have slightly adjusted the by_check, you can update your version of dyn by running the following code:

library(devtools)
devtools::install_github("chaisemartinPackages/did_multiplegt_dyn/R")

If the problem persists, you can share with team email a subset of your data where the problem persists, and we will look it up in more detail. I hope this helps! Best, Diego

lbiagini75 commented 4 months ago

Hey Diego,

Thanks for your quick response and for trying to fix the by_check function. Unfortunately, the solution you suggested didn't solve the problem. I've emailed you the code and a sample of the database where the issue is still happening.

Let me know if you need more information. Thanks again for your support. Best regards, Luigi

chaisemartinPackages commented 4 months ago

Issue closed in private conversation.