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

Error in value[[jvseq[[jjj]]]] : subscript out of bounds #74

Open
notanastronomer opened this issue Jun 18, 2020 · 4 comments
Open

Error in value[[jvseq[[jjj]]]] : subscript out of bounds #74

notanastronomer opened this issue Jun 18, 2020 · 4 comments

Comments

@notanastronomer
Copy link

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

@EdJeeOnGitHub
Copy link
Collaborator

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!

@simondgreenhill
Copy link

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.

@EdJeeOnGitHub
Copy link
Collaborator

Thanks for sharing - this is on my summer to-do list and not forgotten!

@simondgreenhill
Copy link

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)

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

3 participants