bacondecomp icon indicating copy to clipboard operation
bacondecomp copied to clipboard

Does not work when time variable is date? Error in as.Date.numeric(value): 'origin' must be supplied

Open MatthieuStigler opened this issue 5 years ago • 3 comments

Hi

Thanks for the package!! I notice that if the year variable is a date, and I have a never treated group, this will return an error? It seems to be due to this line:

data[is.na(data$treat_time), "treat_time"] <- 99999

As R will complain about a non-valid date?! Maybe could return a 9999-like date is year is date, or at least warn about using dates?

Thanks!

library(bacondecomp)
dat <- bacondecomp::castle[, c("l_homicide", "state", "year", "post")]

## works
df_bacon <- bacon(l_homicide ~ post,
                  data = dat,
                  id_var = "state",
                  time_var = "year")
#>                       type  weight  avg_est
#> 1 Earlier vs Later Treated 0.05976 -0.00554
#> 2 Later vs Earlier Treated 0.03190  0.07032
#> 3     Treated vs Untreated 0.90834  0.08796

## convert to date: does not work
dat2 <- dat
dat2$year <- as.Date(paste0("2000-01-", dat$year-1999))
unique(dat2$year)
#>  [1] "2000-01-01" "2000-01-02" "2000-01-03" "2000-01-04" "2000-01-05"
#>  [6] "2000-01-06" "2000-01-07" "2000-01-08" "2000-01-09" "2000-01-10"
#> [11] "2000-01-11"
bacon(l_homicide ~ post,
      data = dat2,
      id_var = "state",
      time_var = "year")
#> Error in as.Date.numeric(value): 'origin' must be supplied

Created on 2020-06-11 by the reprex package (v0.3.0)

MatthieuStigler avatar Jun 11 '20 22:06 MatthieuStigler

Hi,

Apologies for the delay. I'll be able to have a look at fixing this next week.

It should be relatively simple to implement dates.

EdJeeOnGitHub avatar Jun 18 '20 09:06 EdJeeOnGitHub

Not sure when will be able to get to this. If you're still having a problem I would recommend changing you date to integers (t=1, 2, ..., T)

evanjflack avatar Jul 11 '20 18:07 evanjflack

Had the same issue/error working with actual dates as Date objects.

Decomposition works after converting the dates to integers.

LSYS avatar Jan 20 '21 06:01 LSYS