MatchIt - how to make matching date specific?

521 Views Asked by At

I'm trying to use MatchIt to create two sets of matched investment companies (treatment vs control).

I need to match the treatment companies to the control companies using only data from the 1-3 years proceeding the treatment.

For example if a company received treatment in 2009, then I would want to match it using data from 2009, 2008, 2007 (My after treatment effects dummy would hold a value from 2010 onwards in this case)

I am unsure how to add this selection into my matching code, which currently looks like this:

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

Should I consider using the 'after' treatments effects dummy in some way?

Any tips for how I add this in would be greatly appreciated!

1

There are 1 best solutions below

0
On

There is no straightforward way to do this in MatchIt. You can set a caliper, which requires the control companies to be within a certain number of years from a treated company, but there isn't a way to require that control companies have a year strictly before the treated company. You can perform exact matching on year so that the treated and control companies have exactly the same year using the exact argument.

Another, slightly more involved way is to construct a distance matrix yourself and set to Inf any distances between units that are forbidden to match with each other. The first step would be estimating a propensity score, which you can do manually or using matchit(). Then you construct a distance matrix, and for each entry in the distance matrix, decide whether to set the distance to Inf. FInaly, you can supply the distance matrix to the distance argument of matchit(). Here's how you would do that:

#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)

That should work. You can verify by looking at individual groups of matched companies using match.data():

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

You should see that within subclasses, the control units are 0-2 years below the treated units.