Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MatthieuStigler opened this issue Jun 11, 2020 · 3 comments

Comments

@MatthieuStigler
Copy link

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)

@EdJeeOnGitHub
Copy link
Collaborator

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.

@evanjflack
Copy link
Owner

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)

@LSYS
Copy link

LSYS commented Jan 20, 2021

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

Decomposition works after converting the dates to integers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants