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

Problem with Multisynth #45

Closed
ahmedchaudhryy opened this issue Apr 4, 2021 · 8 comments
Closed

Problem with Multisynth #45

ahmedchaudhryy opened this issue Apr 4, 2021 · 8 comments

Comments

@ahmedchaudhryy
Copy link

Hi,
So I am running multisynth for one of my research projects and it is giving the following error:

Error in Xc[[j]][, (dj - ndim + 1):dj, drop = F] :
subscript out of bounds

There are no missing values in my outcome variable.

Thanks in advance.

@ebenmichael
Copy link
Owner

Could you give some more info? The stack trace, and the function call in particular?

@ahmedchaudhryy
Copy link
Author

ahmedchaudhryy commented Apr 16, 2021

Thank you for your reply.

Here is the traceback call; I hope this helps.
Edit: Removing/changing the number of lags/leads also does not help. The same error persists.

Error in Xc[[j]][, (dj - ndim + 1):dj, drop = F] :
subscript out of bounds

traceback()

7: FUN(X[[i]], ...)
6: lapply(1:J, function(j) {
dj <- ncol(Xc[[j]])
ndim <- min(dj, n_lags)
max_dim <- min(d, n_lags)
mat <- Xc[[j]][, (dj - ndim + 1):dj, drop = F]
n0 <- nrow(mat)
zero_mat <- Matrix::Matrix(0, n0, max_dim - ndim)
Matrix::t(cbind(zero_mat, mat))
})
5: do.call(Matrix::bdiag, lapply(1:J, function(j) {
dj <- ncol(Xc[[j]])
ndim <- min(dj, n_lags)
max_dim <- min(d, n_lags)
mat <- Xc[[j]][, (dj - ndim + 1):dj, drop = F]
n0 <- nrow(mat)
zero_mat <- Matrix::Matrix(0, n0, max_dim - ndim)
Matrix::t(cbind(zero_mat, mat))
}))
4: make_constraint_mats(trt, grps, n_leads, n_lags, Xc, Zc, d, n1)
3: multisynth_qp(X = bal_mat, trt = wide$trt, mask = wide$mask,
Z = wide$Z[, !colnames(wide$Z) %in% wide$match_covariates,
drop = F], n_leads = n_leads, n_lags = n_lags, relative = relative,
nu = 0, lambda = lambda, V = V, time_cohort = time_cohort,
donors = donors, eps_rel = eps_rel, eps_abs = eps_abs, verbose = verbose)
2: multisynth_formatted(wide = wide, relative = T, n_leads = n_leads,
n_lags = n_lags, nu = nu, lambda = lambda, V = V, force = force,
n_factors = n_factors, scm = scm, time_cohort = time_cohort,
time_w = F, lambda_t = 0, fit_resids = TRUE, eps_abs = eps_abs,
eps_rel = eps_rel, verbose = verbose, long_df = long_df,
how_match = how_match, ...)
1: multisynth(minwage_binary ~ crb, state, year, cfri, fixedeff = TRUE,
n_lags = 6, n_leads = 6)

@frederickluser
Copy link

Dear Eli

Thank you for your amazing work and congrats for the publication!
I am getting exactly the same error for my project. Do you have any idea where the problem might be?

Best, Frederic

@sethneller
Copy link

I'm having this exact issue as well. I'm wondering if it has something to do with always-treated units as I can replicate the error message using the vignette data if I recode at least of the states to have cbr=1 for the entire period. Unfortunately, when I drop my always-treated units, R-studio encounters a fatal error so this doesn't really fix things. @frederickluser, do you also have always-treated units in your data?

I'm also attaching the data file that I'm using in case that's helpful in anyway.

Thanks to Eli and team for putting this package together!

analytic_file.txt

@frederickluser
Copy link

@sethneller Thanks for your comment, I played around with it and deleted all the treatments that took place in the first two and last two periods. Like this it would work.

@ebenmichael
Copy link
Owner

@sethneller thanks for pointing this out!

There are two issues going on. First, if there are always treated units then the method won't work. This seems to be the issue for @frederickluser and @ahmedch92. Second if you're including a fixed effect (fixedeff = TRUE which is the default) and a unit has only 1 pre-treatment outcome, then the optimization problem is ill-specified and R breaks. This was the other problem that @sethneller was having.

I just added some checking code that'll give a more interpretable error message for both these cases, pointing out which units are causing the problems. Let me know if that works.

@sethneller
Copy link

@ebenmichael, thank you so much for your help! That definitely fixed everything on my end and the error messages were super informative. Looking forward to using this method!

@ebenmichael
Copy link
Owner

Great, glad this worked!

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