Open notanastronomer opened 4 years ago
Hi,
Are you able to create a reprex or add some example data?
It's hard to debug without some more information as a whole host of things could cause indexing issues.
Thanks!
I ran into the same error, and after some debugging realized it was because I had mis-specified my formula (I was regressing my outcome on the treatment variable, rather than on the interaction of treatment and post). Perhaps @notanastronomer had a similar issue?
In my case the problem was purely user error, but perhaps it would be possible to include a more informative error message. The code was erroring out in the create_treatment_groups
function, specifically on this line. The problem was that the two_by_twos
dataframe was empty since I had fed in a variable that had no variation in the treatment time. One possible fix to the problem I encountered (again, not sure if this is the same as OP's), is to just check that two_by_twos
has positive length and throw an (informative) error if not.
Thanks for sharing - this is on my summer to-do list and not forgotten!
Hi Ed,
Sounds good--here's a quick reprex illustrating the issue I was having in case helpful. Thanks for creating and maintaining this cool package!
library(bacondecomp)
# set up some fake data
fake_data = expand.grid(treat = c(0, 1), post=c(0, 1))
fake_data$id = rep(c(1, 2), 2)
n = nrow(fake_data)
fake_data$outcome = rnorm(n)
fake_data$treat_post = fake_data$treat * fake_data$post
# this errors
bacon(outcome ~ treat, data=fake_data, id_var='id', time_var='post')
#> Error in value[[jvseq[[jjj]]]]: subscript out of bounds
# this runs
bacon(outcome ~ treat_post, data=fake_data, id_var='id', time_var='post')
#> type weight avg_est
#> 1 Treated vs Untreated 1 -2.75051
#> treated untreated estimate weight type
#> 2 1 99999 -2.750506 1 Treated vs Untreated
Created on 2021-04-30 by the reprex package (v2.0.0)
Have balanced panel as variable dat.
df_bacon <- bacon(outcome ~ order, data = dat, id_var = "state_abbrev", time_var = "date_weekly")
Get: Error in value[[jvseq[[jjj]]]] : subscript out of bounds