you have helped me tremendously over the past years and so far, I could find an answer to any the question I had! Thanks to anyone active in this community, I don't know what I would have done without you! But over the past days, I have been unable to find a solution for the following problem at hand:
Situation
- I have a panel data set and hence a fixed number of observations for many ids over several years from 1980-2017 called
data1
. - In addition, I have several treatment events (1990, 1999, 2009, 2010 and 2011) e.g. state legislations that result in treated and untreated (possible controls) companies.
Goal
Out of the possible controls, I want to match two controls to each treated company given pre-defined criteria and thus, reduce the group of controls to have a better matched/balanced sample. I do this to analyse the effect on a variable of interest over a long time frame of t-7 and t+7 given the time t of legislation i with a DiD analysis.
My insufficient take
I did the matching for one legislation/point in time in 2009 with the package library(matchit)
. This means, I did the matching on cross-sectional data data2
(a subsample of data1
) and generated the following code:
m.out1 <- matchit(treatment ~ covariate1 + covariate2 + covariate3, data=data2,
method="nearest",distance="mahalanobis",
exact = ~covariate4,
ratio = 2)
The outcome is exactly what I want it to be and after assessing the balance of the matched sample I am more than happy with the outcome. For my DiD analysis I transformed the cross-sectional data data2
back to panel data (merging with default data1
).
Problem
If I follow the above procedure for each legislation/point in time (e.g. 1990, 1999, 2009, 2010 and 2011) I end up with 5 different data sets. If I would then combine them again for my DiD analysis, I could have overlapping controls for different post legislation periods. In numbers: Instead of having e.g. 100 controls for my 50 treated companies across the 5 legislations (10 treated per event) I would end up with maybe 90 unique controls. Furthermore, I would only match correctly the controls for each subsample but not for the full sample I want to analyse in the first place (all legislations) This is especially the case for the later legislations that have overlapping time frames post legislation/event. What I think would be the solution is the following:
Transform all legislations into one cross-sectional data set data3
and then, include a line of code that would only allow a control to be used once. Hence, the data set could include duplicates of an id for different events. The data would somehow look like this:
ID year treated
1 2009 1
2 2009 0
3 2009 0
4 2011 1
2 2011 0
5 2011 0
In this example, id 2 could be a control in 2009 and 2011. I want it to be a control (given my specifications from above) for either 2009 or 2011, whatever is the best for the full sample! Hence, the id 2 would be "removed" and thus cannot be matched again in 2011. I rephrase it again: it is similar to matching without replacement but over several points in time. I want that each control is only "assigned" to one legislation/event and the given treated companies.
Would anyone of you know how to implement this? Do you think this makes no sense and rather match the controls for each legislation-subsample and then potentially run into controls being used for multiple events?
MatchIt
to implement this form of matching but it's not ready for prime time. I will let you know when it is. You are not the first to ask for this feature. $\endgroup$