Announcement

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

  • Overlay two coefplots

    Hi Stata users,

    I am trying to overlay two coefplots but I am having some difficulty. Here is my command:

    Code:
    keep if l2h==1
    
    summ     event_time
        g         t = event_time - r(min)
        summ     t if event_time == -1
        local     true_neg = r(mean)
    
    reghdfe    breadth_search c.ra_delta##ib`true_neg'.t ///
                    LWbas_male age LWbas_married LWbas_immigrant LWbas_child LWbas_pre LWbas_pre9 ///
                    LWbas_s_high LWbas_l_high LWbas_s_univ LWbas_l_univ LW5_emp_mon_last5y ///
                    LWhist_empbef1 LW5_av_dur LW5_last_dur LWhist_income_bef1 LW5_welfare5, ///
                    cluster(referal_officeid) absorb(referal_year referal_CWid llm_kod future_officeid) 
        estimates store l2h
    
        coefplot (l2h, msymbol(Sh) msize(small) label(RA_Spillover_l2h)), ///
        keep(10.t#c.ra_delta 11.t#c.ra_delta 12.t#c.ra_delta ///
        13.t#c.ra_delta 14.t#c.ra_delta 15.t#c.ra_delta 16.t#c.ra_delta 17.t#c.ra_delta 18.t#c.ra_delta 19.t#c.ra_delta 20.t#c.ra_delta) ///
        rename(10.t#c.ra_delta= "t=-4" 11.t#c.ra_delta= "t=-3" 12.t#c.ra_delta= "t=-2" ///
        13.t#c.ra_delta ="t=-1" 14.t#c.ra_delta= "t=0" 15.t#c.ra_delta= "t=1" 16.t#c.ra_delta ="t=2" 17.t#c.ra_delta ="t=3" 18.t#c.ra_delta ="t=4" 19.t#c.ra_delta ="t=5" 20.t#c.ra_delta ="t=6") ///
        omitted baselevels xline(4, lcolor(gs5) lp(dash) lwidth(medium)) ///
        yline(0, lcolor(black) lp(dash) lwidth(medium))  ///
        legend(size(vsmall)) ylabel(-.8(.4).8, labsize(vsmall)) xlabel(, labsize(vsmall)) noci recast(connected) ciopts(recast(rcap)) lcolor(red) lp(dash) vertical
    Code:
    keep if l2h==0
    
    summ     event_time
        g         t = event_time - r(min)
        summ     t if event_time == -1
        local     true_neg = r(mean)
        
        reghdfe        breadth_search c.ra_delta##ib`true_neg'.t ///
                    LWbas_male age LWbas_married LWbas_immigrant LWbas_child LWbas_pre LWbas_pre9 ///
                    LWbas_s_high LWbas_l_high LWbas_s_univ LWbas_l_univ LW5_emp_mon_last5y ///
                    LWhist_empbef1 LW5_av_dur LW5_last_dur LWhist_income_bef1 LW5_welfare5, ///
                    cluster(referal_officeid) absorb(referal_year referal_CWid llm_kod future_officeid) 
        estimates store h2l
        
        coefplot (h2l, msymbol(Sh) msize(small) label(RA_Spillover_h2l)), ///
        keep(9.t#c.ra_delta 10.t#c.ra_delta 11.t#c.ra_delta 12.t#c.ra_delta ///
        13.t#c.ra_delta 14.t#c.ra_delta 15.t#c.ra_delta 16.t#c.ra_delta 17.t#c.ra_delta 18.t#c.ra_delta 19.t#c.ra_delta) ///
        rename(9.t#c.ra_delta ="t=-4" 10.t#c.ra_delta= "t=-3" 11.t#c.ra_delta= "t=-2" 12.t#c.ra_delta= "t=-1" ///
        13.t#c.ra_delta ="t=0" 14.t#c.ra_delta= "t=1" 15.t#c.ra_delta= "t=2" 16.t#c.ra_delta ="t=3" 17.t#c.ra_delta ="t=4" 18.t#c.ra_delta ="t=5" 19.t#c.ra_delta ="t=6") ///
        omitted baselevels xline(4, lcolor(gs5) lp(dash) lwidth(medium)) ///
        yline(0, lcolor(black) lp(dash) lwidth(medium))  ///
        legend(size(vsmall)) ylabel(-.8(.4).8, labsize(vsmall)) xlabel(, labsize(vsmall)) noci recast(connected) ciopts(recast(rcap)) lcolor(red) lp(dash) vertical
    (i) I also want to draw a common xline at 0 but this point is defined differently in these two models.
    (ii) I do not want to connect the coefficients between time=-1 and time=0.

    Any suggestion or help would be highly appreciated.

    Best,
    Zariab Hossain
    Uppsala University

  • #2
    Hi ,

    I have come up with the following code that helped me to overlay the above coefplots. I do not need confidence interval but I want to place the coefficients one the top of each other (NOT side by side!). I want all the point estimates to be connected except between t=-1 and t=0. How can I do that?

    Here is the code:

    Code:
        coefplot (l2h, keep(10.t#c.ra_delta 11.t#c.ra_delta 12.t#c.ra_delta 13.t#c.ra_delta 14.t#c.ra_delta 15.t#c.ra_delta 16.t#c.ra_delta 17.t#c.ra_delta 18.t#c.ra_delta 19.t#c.ra_delta 20.t#c.ra_delta) rename(10.t#c.ra_delta= "t=-4" 11.t#c.ra_delta= "t=-3" 12.t#c.ra_delta= "t=-2" 13.t#c.ra_delta ="t=-1" 14.t#c.ra_delta= "t=0" 15.t#c.ra_delta= "t=1" 16.t#c.ra_delta ="t=2" 17.t#c.ra_delta ="t=3" 18.t#c.ra_delta ="t=4" 19.t#c.ra_delta ="t=5" 20.t#c.ra_delta ="t=6")) (h2l, keep(9.t#c.ra_delta 10.t#c.ra_delta 11.t#c.ra_delta 12.t#c.ra_delta 13.t#c.ra_delta 14.t#c.ra_delta 15.t#c.ra_delta 16.t#c.ra_delta 17.t#c.ra_delta 18.t#c.ra_delta 19.t#c.ra_delta) rename(9.t#c.ra_delta ="t=-4" 10.t#c.ra_delta= "t=-3" 11.t#c.ra_delta= "t=-2" 12.t#c.ra_delta= "t=-1" 13.t#c.ra_delta ="t=0" 14.t#c.ra_delta= "t=1" 15.t#c.ra_delta= "t=2" 16.t#c.ra_delta ="t=3" 17.t#c.ra_delta ="t=4" 18.t#c.ra_delta ="t=5" 19.t#c.ra_delta ="t=6")), yline(0, lcolor(black) lp(dash) lwidth(medium)) noci vertical xline(4) ylabel(-.8(.4).8, labsize(vsmall)) xlabel(, labsize(vsmall))
    Here is the plot:



    Best,
    Zariab Hossain
    Attached Files
    Last edited by Zariab Hossain; 07 Jan 2025, 05:14.

    Comment


    • #3
      I solved the problem.

      Best,
      Zariab Hossain

      Comment

      Working...
      X