Skip to content

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

@MatthieuStigler

Description

@MatthieuStigler

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions