insongkim / PanelMatch

117 stars 35 forks source link

errors with update #38

Closed elsavoytas closed 5 years ago

elsavoytas commented 5 years ago

Hi,

My PanelMatch and PanelEstimate functions were running ok, but since I updated, I have not been able to successfully run these functions. I get one of two errors when running PanelMatch:

  1. Error in model.frame.default(form, x, na.action = NULL) : variable lengths differ and
  2. Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels

I've tried some troubleshooting but can't figure it out. I'm happy to send on sample code/data.

Thanks!

adamrauh commented 5 years ago

hi @elsavoytas, thanks for using the package! Could you provide some sample code? I'm guessing that you just need to update some syntax to work with the new updates.

elsavoytas commented 5 years ago

Of course!

matches <- PanelMatch(lag = 4, unit.id = "nameID", time.id = "time.id", treatment = "reparation", outcome.var = "vote", qoi = "att", refinement.method = "mahalanobis", data = rettig, match.missing = T, covs.formula = ~ lag('vote', 1:4), size.match = 5, verbose = T,lead = 0:12)

returns

Error incontrasts<-(tmp, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels

and

`matches.val <- PanelMatch(lag = 4, unit.id = "nameID", time.id = "time.id", treatment = "reparation", outcome = "vote", qoi = "att", refinement.method = "mahalanobis",

use.diagonal.variance.matrix = T,

                      data = new_df, match.missing = T,
                      covs.formula = ~ lag('vote', 1:4)+gender+birthyear ,
                      size.match = 5, verbose = T,lead = 0:12)`

returns Error in model.frame.default(form, x, na.action = NULL) : variable lengths differ (found for 'gender') though all the vectors are the same length.

Thanks!

adamrauh commented 5 years ago

Could you try changing the syntax of the covs.formula argument? Specifically, change lag('vote', 1:4) to I(lag(vote, 1:4)) in both specifications? We made some changes to that syntax so that things work better internally.

elsavoytas commented 5 years ago

Looks like that did it! Thanks for the quick assistance @adamrauh!