To run a difference in differences (DiD) analysis in R, you can use a package called “plm” (Panel Data Econometrics in R). The approach involves comparing pre- and post-treatment outcomes of a treatment group to those of a control group that did not receive the intervention. Here are the basic steps to run a DiD analysis:
main.r32 chars3 lines
main.r29 chars2 lines
main.r157 chars3 lines
The explanatory variable treatment * time_period
permits us to see how the effect of the treatment varies between the different time periods.
main.r19 chars2 lines
There are of course different assumptions that need to be met to make a good DiD estimate. It is recommended to also plot the average outcomes pre-treatment and post-treatment over time and see if there are discontinuities in these trends that may suggest another explanation for your results.
gistlibby LogSnag