Reputation: 11
I'm running a dif-in-dif estimation and using the MatchIt package to match my treatment and control groups by their distance to a certain location (nearest neighbour matching, logit model, caliper = 0.25).
Everything is ok with the actual matching, however I ran across this kind of plot in a paper I read:
I'm a bit confused, how is it possible to plot propensity scores before matching since the matching itself gives the propensity scores? So if anyone is familiar with this kind of plotting I'd appreciate help. Here's my code so far, which only gives the density functions after matching for treatment (Near) and control.
m.df <- matchit(Near ~ Distance_to_center, data = df, method = "nearest", distance = "logit", caliper =0.25)
mdf <- match.data(m.df,distance = "pscore")
df <- mdf
plot(density(df$pscore[df$Near==1]))
plot(density(df$pscore[df$Near==0]))
Upvotes: 1
Views: 3240
Reputation: 4414
Matching does not give the propensity scores. Propensity scores are first estimated, then matchit()
matches units on the propensity scores.
You can extract the propensity scores for the whole sample from the matchit
object. What you did when you used match.data()
is extract the propensity scores for only the matched data. The propensity scores for the whole sample are stored in m.df$distance
. So, to manually generate those plots, you can use:
plot(density(m.df$distance[df$Near==1]))
plot(density(m.df$distance[df$Near==0]))
before using match.data()
.
You can also use the cobalt
package to automatically generate these plots:
bal.plot(m.df, var.name = "distance", which = "both")
will generate the same density plots in one simple line of code.
Upvotes: 1