I am trying to use MatchIt
to perform Propensity Score Matching (PSM) for my panel data which contains following a group of participants (participant_uuid) from 12 months before treatment to 12 months after treatment, i.e. we have complete 24 observations per participant. I am performing the matching to prepare a dataset for later calculating Diff-in-diff models. As with diff-in-diff I want to find how the reaction to treatment might vary between groups I am matching based on the 12 months prior treatment. My code currently looks like this:
match.nearestneighbour <- matchit(grouping_variable ~ characteristic1 + characterictic2 + charcteristic3, data = dataset_12months_pre_treatment, distance = "glm", method = "nearest", m.order = "largest", replace = TRUE, exact = c("month_relative_to_treatment"))
I realized this code matches on individual unit level (i.e. selects the best participant_uuid for each month_relative_to_treatment matchig to each of the observations treatment group months). How to change the rstudio code to find the nearest neighbor not per month/observation but the participant_uuid in control group with nearest distance to participant_uuid in treatment group, aggregated across the 12 months considered? Any hints are much appreciated.