Cannot Save the Matched Sample after matchit(): Error in cbind_all(x) : Argument 2 must have names

好久不见. 提交于 2021-01-29 05:36:54

问题


I used thematchit() and Method="nearest". But when I try to save the output into a data.frame by match.data(), the error shows up:

Error in cbind_all(x) : Argument 2 must have names.

My Code:

a = matchit(Y ~ Year + IndustryCode + ROA + Debt, 
            data=data, method="nearest", ratio=1)
b = match.data(a)
  • Year variable = 2003, 2004 etc.
  • IndustryCode = A02, A21 etc.
  • other variables are numeric.

Those are the warnings after matchit():

Warning messages:
1: glm.fit: fitted probabilities numerically 0 or 1 occurred
2: In matchit2nearest(c(FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, :
Fewer control than treated units and matching without replacement. Not all treated units will receive a match. Treated units will be matched in the order specified by m.order: largest.

What do you think is the reason?


回答1:


The first warning is because your propensity score model yields perfect predictions. This indicates a small sample size or a violation of positivity (i.e., that your treatment and control groups are fundamentally different). You don't have to worry about this so much if you still get good balance and a good remaining sample size.

The second warning is because your treated group is larger than your control group. If you're doing 1:1 matching without replacement, all the control units will be used up before all the treated units get a match. To remedy this, you need to match with replacement or think about whether you actually want to generalize to the control population and switch the labels on the treatment groups. You can do this by creating a new variable, say notY, which is 1 - Y and then performing the same operations.

The error is because I imagine you're using a tibble rather than a standard data frame. MatchIt isn't fully compatible with tibbles. Before you run your analysis, try running data <- as_data_frame(data) to convert it back to a data frame. You might need to load in the tibble package with library() before you do this. The reason I believe a tibble might be your problem is that match.data() doesn't call cbind_all(); it calls cbind(), which is a generic method that dispatches to class method, in this case, the method for a tibble. The cbind method for a tibble calls cbind_all().




回答2:


This error happened to me, and it was because data had groups. So, I made sure to ungroup(data) first, and I did not get the error.



来源:https://stackoverflow.com/questions/53009833/cannot-save-the-matched-sample-after-matchit-error-in-cbind-allx-argument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!