JMSLab / eventstudyr

Other
24 stars 1 forks source link

Informative error message when dataset contains time gaps #52

Closed AakaashRao closed 2 weeks ago

AakaashRao commented 3 months ago

I run into the following uninformative error message when running EventStudy on a dataset that contains gaps in the time variable for all idvar values.

Error: Not a matrix.
In addition: Warning messages:
1: In EventStudy(estimator = "OLS", data = data, outcomevar = "n_households",  :
  Dataset is unbalanced.
2: In EventStudy(estimator = "OLS", data = data, outcomevar = "n_households",  :
  Note: gaps of more than one unit in the time variable 'date' were detected. Treating these as gaps in the panel dimension.

My specific case is using calendar date as the time variable for a dataset lacking weekend observations. The values passed to timevar therefore look like c(1,2,3,4,5,8,9,10,11,12,15, ...).

I solved the issue by re-generating the numeric date variable without gaps:

data = data %>% mutate(date = dplyr::dense_rank(date))

It might be helpful to add a more informative error message in case others have the same use case?

santiagohermo commented 3 months ago

Hi @AakaashRao! Thanks for pointing this out.

The goal here is to make sure that we take proper leads and lags to compute first differences within each unit. In your case you are fine with taking differences between a Monday and a Friday, right? Then your solution makes sense.

I think the error message is informative, it tells the user what the code is doing with the time dimension. What additional information in the error message would have helped? Maybe suggesting to relabel the time variable?

santiagohermo commented 2 weeks ago

Closed due to inactivity. Feel free to reopen if you want to discuss more @AakaashRao

AakaashRao commented 1 week ago

@santiagohermo , sorry for the delay! You're right -- this reflected a misunderstanding on my part and the error message is plenty informative as it is. Thanks for the great work on this package!

santiagohermo commented 1 week ago

Thanks @AakaashRao!