MatchIt-如何使匹配日期特定



我正试图使用MatchIt创建两组匹配的投资公司(治疗与控制(。

我需要仅使用进行治疗1-3年的数据将治疗公司与对照公司进行匹配。

例如,如果一家公司在2009年接受了治疗,那么我想使用2009年、2008年和2007年的数据来匹配它(在这种情况下,我的治疗后效果假人将保持从2010年起的值(

我不确定如何将此选择添加到我的匹配代码中,该代码目前看起来如下:

matchit(签字人~总美元+棕色美元+国家+战略,数据=面板6,方法="满"(

我是否应该考虑以某种方式使用"治疗后"效果假人?

任何关于我如何添加此内容的提示都将不胜感激!

MatchIt中没有直接的方法可以做到这一点。你可以设置一个卡尺,要求控制公司与被处理公司相隔一定年限,但没有办法严格要求控制公司在被处理公司之前有一年的时间。您可以使用exact参数对年份执行精确匹配,以便接受治疗的公司和控制公司的年份完全相同。

另一种稍微复杂一点的方法是自己构造一个距离矩阵,并将禁止相互匹配的单元之间的任何距离设置为Inf。第一步是估计倾向得分,您可以手动或使用matchit()进行评估。然后构造一个距离矩阵,对于距离矩阵中的每个条目,决定是否将距离设置为Inf。同样,您可以将距离矩阵提供给matchit()distance自变量。以下是您的操作方法:

#Estimate the propensity score
ps <- matchit(signatory ~ totalUSD + brownUSD + country + strategy, 
data = panel6, method = NULL)$distance
#Create the distance matrix
dist <- optmatch::match_on(signatory ~ ps, data = panel6)
#Loop through the matrix and set set disallowed matches to Inf
t <- which(panel6$signatory == 1) 
u <- which(panel6$signatory != 1)
for (i in seq_along(t)) {
for (j in seq_along(u)) {
if (panel6$year[u[j]] > panel6$year[t[i]] || panel6$year[u[j]] < panel6$year[t[i]] - 2)
dist[i,j] <- Inf
}
}
#Note: can be vectorized for speed but shouldn't take long regardless
#Supply the distance matrix to matchit() and match
m <- matchit(signatory ~ totalUSD + brownUSD + country + strategy, 
data = panel6, method = "full", distance = dist)

这应该行得通。您可以使用match.data():查看匹配公司的单个组来进行验证

md <- match.data(m, data = panel6)
md <- md[with(md, order(subclass, signatory)),]
View(md) #assuming you're using RStudio

您应该看到,在子类中,控制单位比处理单位低0-2年。

最新更新