Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plotting parallel trends for DiD model post xtreg estimation

    Hi everyone,
    I hope you're well.

    I am hoping to get your guidance on the best way to go about graphing parallels trends after running this:
    xtset Firm_ID date
    gen Post = 1 if Year>2020
    replace Post =1 if Year==2020 & Quarter>3
    replace Post = 0 if Post==.
    xtile Treat = E_Score
    replace Treat=0 if Treat==1
    replace Treat=1 if Treat==2
    gen DiD = Post * Treat

    xtreg Spread Post Treat DiD E_Score Issue_Size Liquidity Maturity RatingScale Firm_Size ROA Firm_Leverage, fe vce(cluster Firm_ID)



    I am hoping for the graph to look something like this:
    Click image for larger version

Name:	Basic_DID_Illustration.jpg
Views:	1
Size:	175.8 KB
ID:	1776101



  • #2
    Here is an example of how one might do it using the v18 hospdd.dta file that Stata uses to demonstrate difference in difference with the xtdidregress command. See here for a demonstration.
    Code:
    use "https://www.stata-press.com/data/r18/hospdd.dta", clear
    xtset hospital
    xtdidregress (satis) (procedure), group(hospital) time(month) aeq    // atet = .8479(.03)
    estat trendplots
    Produces the following plot:
    Click image for larger version

Name:	estat ptrends plot.png
Views:	1
Size:	85.7 KB
ID:	1776111

    In order to recreate the linear-trends model plot, I created a time-invariant variable for whether a hospital was ever treated and then ran a fixed effect model with ever treated interacted with month. These are the estimated treatment effects for each month for the group of hospitals that were treated or not. You could, in theory, put those estimates into a little data set and plot them, or you can force margins to give you the quantities of interest and plot the marginal effects. Note that to do so, you have to use the noestimcheck option. If you don't use that, then marginsplot will say the effects of interest cannot be estimated:
    Code:
    bysort hospital: egen intrt = max(procedure)
    xtreg satis i.intrt##i.month, vce(robust) fe
    margins intrt, over(month) noestimcheck nose
    marginsplot, xdimension(month) noci xline(3)
    The marginsplot is below. You will note small differences between this and the plot from estat trendplots. This may not be the procedure Stata is using for estat trendplots, but it is pretty close. I would be curious if others have a better intuition for how to get the graph from estat trendplots by hand:
    Click image for larger version

Name:	marginsplot ptrends.png
Views:	1
Size:	62.7 KB
ID:	1776112

    Last edited by Erik Ruzek; 16 Apr 2025, 16:52. Reason: Changed estat ptrends to estat trendplots in explanation

    Comment

    Working...
    X