Search code examples
rmatchinglongitudinalpropensity-score-matching

PSM in R with specific lines


to get matched pairs due to PSM ("Matchit"-Package and Method = full) i need to specifiy my command for my longitudinal data frame. Every Case has several obeservations but i only need the first observation per patient to be included in the Matching. So the matching should be based on every patients' first observation but my later analysis should include the complete dataset of each patient with all observations.

Has anyone an idea how to achieve this?

I tried using a data subset (first observation per patient) but wasn't able to get the matching included in the data set (with all observations per patient) using "Match.data".

Thanks in advance Simon (desperately writing his masters thesis)


Solution

  • My udnerstanding is that you want to create matches at just the first time point but have those matches be identified for each unit at all time points. Fortunatly, this is pretty straightforward: just perform the matching at the first time point and then merge the matched dataset with the full dataset. Here is how this might look. Let's say your original long dataset is d and has an ID column id and a time column time.

    m <- matchit(treat ~ X1 + X2, data = subset(d, time == 1), method = "full")
    md1 <- match.data(m)
    d <- merge(d, md1[c("id", "subclass", "weights")], by = "id", all.x = TRUE)
    

    Your new dataset should have two new columns, subclass and weights, which contain the matching subclass and matching weight for each unit. Rows with identical IDs (i.e., rows corresponding to the same unit at multiple time points) will have the same value of subclass and weight.