Announcement

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

  • rdplot (part of rdrobust) problem?

    Dear All, This is a related problem as here (https://www.statalist.org/forums/for...ange-in-x-axis). Please search rdrobust and install (SJ-17-2 st0366_1) code/data. The code is
    Code:
    use rdrobust_rdsenate.dta, clear
    rdplot vote margin, graph_options(title(RD plot))
    and the graph is
    Click image for larger version

Name:	rdplot.png
Views:	1
Size:	69.3 KB
ID:	1591510


    Suppose that, for some reason, I just want to show the graph with x-axis ranging from -100 to 50 (not to 100). Any suggestions are highly appreciated.
    Ho-Chuan (River) Huang
    Stata 17.0, MP(4)

  • #2
    My suggestion from the other thread still stands - you can just run the regression and plot the graph manually. I don't have access to the rdrobust_rdsenate.dta file, so here's an illustration of the polynomial fit using auto.dta:

    Code:
    clear *
    sysuse auto
    rdplot mpg weight, graph_options(title(RD plot)) c(2500) genvars
    forvalue x=2/4{
        gen weight`x' = weight^`x'
    }
    reg mpg weight* if weight>=2500
    predict yhat1
    reg mpg weight* if weight<=2500
    predict yhat2
    twoway line yhat1 weight if weight>=2500 & weight<3500,sort(weight) lcolor(gs0)|| line yhat2 weight if weight<=2500,sort(weight) lcolor(gs0) || scatter rdplot_mean_y rdplot_mean_x if weight<3500, mcolor(gs7) msymbol(O)||, name(graph3) yla(10(10)40) xline(2500,lcolor(gs0)) title("Non-RD plot") legend(order(1 "Polynomial fit of order 4" 3 "Sample average within bin")) xla(1500(1000)3500)
    A comparison of the results:
    Click image for larger version

Name:	rdplot.png
Views:	1
Size:	47.1 KB
ID:	1591523
    Click image for larger version

Name:	nonrdplot.png
Views:	1
Size:	45.6 KB
ID:	1591524

    Comment


    • #3
      Dear Ali, Thanks again. I will give it a try tomorrow.
      Ho-Chuan (River) Huang
      Stata 17.0, MP(4)

      Comment


      • #4
        You get a discontinuity in the graph in #2 where there is a break. This could be fixed by extending the end-point of the line in the first subgraph. An alternative is to use the original graph's data. For your graph in #1

        Code:
        tempfile s0 s1 s2
        forval i=0/2{
            use rdrobust_senate.dta, clear
            qui rdplot vote margin, graph_options(title(RD plot))
            serset `i'
            serset use, clear
            save `s`i''
        }
        use `s0', clear
        merge 1:1 _n using `s1', nogen
        merge 1:1 _n using `s2', nogen
        
        twoway (scatter rdplot_mean_y rdplot_mean_bin if rdplot_mean_bin<=50, ///
        sort msize(small)  mcolor(gs10)) (line y_plot_l x_plot_l, lcolor(black) sort ///
        lwidth(medthin) lpattern(solid)) (line y_plot_r x_plot_r if x_plot_r<=50, lcolor(black) ///
        sort lwidth(medthin) lpattern(solid)),  xline(0, lcolor(black) lwidth(medthin)) ///
        legend(cols(2) order(2 "Sample average within bin" 3 "Polynomial fit of order 4"))
        Res.:
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	49.4 KB
ID:	1591531

        Comment


        • #5
          @River Huang Here is my sulution.Mm,maybe the graph is a little diferent from rdplot in the left side.
          Code:
          use rdrobust_rdsenate.dta, clear
          rdplot vote margin, genvars graph_options(title(RD plot))
          twoway (scatter rdplot_mean_y rdplot_mean_x if margin<0,sort mlabsize(small))  ///
                 (scatter rdplot_mean_y rdplot_mean_x if inrange(margin,0,50),sort) ///
                 (line rdplot_hat_y margin if margin<0 ,sort)  ///
                 (line rdplot_hat_y margin if inrange(margin,0,50) ,sort), ///
                 xline(0) legend(off) scheme(s1color)

          Attached Files
          Last edited by Raymond Zhang; 27 Jan 2021, 05:40. Reason: @Andrew Musau #4 solve the problem perfectly.My sollution also gets a discontinuity.
          Best regards.

          Raymond Zhang
          Stata 17.0,MP

          Comment


          • #6
            Dear Andrew, Thanks a lot for this helpful suggestion.
            Ho-Chuan (River) Huang
            Stata 17.0, MP(4)

            Comment


            • #7
              Dear Raymond, Thanks a lot for this helpful suggestion.

              Ho-Chuan (River) Huang
              Stata 17.0, MP(4)

              Comment

              Working...
              X