【问题标题】:MatchIt - how to make matching date specific?MatchIt - 如何指定匹配日期?
【发布时间】:2021-08-27 04:38:13
【问题描述】:

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

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

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

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

matchit(signatory ~ totalUSD + brownUSD + country + strategy, data = panel6, method = "full")

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

任何关于如何添加它的提示将不胜感激!

【问题讨论】:

    标签: matching nearest-neighbor mahalanobis propensity-score-matching


    【解决方案1】:

    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 年。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多