Announcement

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

  • Coefplot - adding confidence interval

    Dear community,

    I created this plot for the sector-level coefficients of a gravity model (see attached). As I want to compare these coefficients with an aggregate estimate, I would like to add a grey band, for the confidence interval of this aggregate estimate. For now, I have only defined the two limits of the confidence interval (ll and ul), but I don't manage to create a band out of them inside coefplot (I tried with the addplot(rarea ll ul range, color()) line, but it doesn't produce anything. Any hint is highly appreciated!

    This is my code (I have stored the estimation results of the sector-level regressions as separate .ster files (e.g. sector22.ster)):

    gen ll=0.158
    gen ul=2.67
    gen range = cond(_n==1, _n-.5, _n+.5)

    coefplot (sector1, aseq("Sector 1")) (sector2, aseq("Sector 2")) (sector3, aseq("Sector 3")) (sector4, aseq("Sector 4")) ///
    (sector5, aseq("Sector 5")) (sector6, aseq("Sector 6")) (sector7, aseq("Sector 7")) (sector8, aseq("Sector 8")) ///
    (sector9, aseq("Sector 9") ciopts(color(green) recast(rcap)) mcolor(green)) ///
    (sector10, aseq("Sector 10")) (sector11, aseq("Sector 11")) (sector12, aseq("Sector 12")) (sector13, aseq("Sector 13")) ///
    (sector14, aseq("Sector 14")) (sector15, aseq("Sector 15")) ///
    (sector16, aseq("Sector 16") ciopts(color(orange) recast(rcap)) mcolor(orange)) ///
    (sector17, aseq("Sector 17")) ///
    (sector18, aseq("Sector 18") ciopts(color(orange) recast(rcap)) mcolor(orange)) ///
    (sector19, aseq("Sector 19")) ///
    (sector20, aseq("Sector 20")) ///
    (sector21, aseq("Sector 21")) (sector22, aseq("Sector 22")) (sector23, aseq("Sector 23")) , ///
    keep(lngdp_o) ///
    ciopts(recast(rcap) color(blue)) ///
    msymbol(O) mcolor(blue) ///
    ytitle("Coefficient of source GDP (log)") ///
    xtitle(" ") ///
    yline (1.417, lcolor(red)) ///
    yline (0, lcolor(black)) ///
    xlabel( , labcolor(none) angle(0) labsize(medium)) ///
    vertical aseq swapnames nokey ///
    level(90) ///
    xtitle("Sector") ///
    addplot(rarea ll ul range, color(gs8%40)) ///
    xlabel(1 "11" 2 "21" 3 "22" 4 "23" 5 "31" 6 "32" 7 "33" 8 "42", add custom labcolor(black) labsize(*0.64)) ///
    xlabel(9 "44", add custom labcolor(green) labsize(*0.64)) ///
    xlabel(10 "45" 11 "48" 12 "49" 13 "51" 14 "52" 15 "53", add custom labcolor(black) labsize(*0.64)) ///
    xlabel(16 "54", add custom labcolor(orange) labsize(*0.64)) ///
    xlabel(17 "55", add custom labcolor(black) labsize(*0.64)) ///
    xlabel(18 "56", add custom labcolor(orange) labsize(*0.64)) ///
    xlabel(19 "61" 20 "62" 21 "71" 22 "72" 23 "81", add custom labcolor(black) labsize(*0.64))
    drop ll ul range


    Best Noemi
    Attached Files

  • #2
    coefplot is from SSC, as you are asked to explain (FAQ Advice #12). If you have the aggregate estimate stored, then just plot it. Otherwise, if your intention is to shade part of the plot area, see https://journals.sagepub.com/doi/pdf...867X1601600315. There is no reproducible example, so the following example illustrates.

    Code:
    sysuse auto, clear
    regress mpg ibn.rep78
    est sto A
    coefplot (A, drop(_cons) ) ///
    (A, mc(none) drop(_cons) ciopts(recast(rarea) bcolor(gray%30) )), ///
    ylab(-15(5)5) xlab(1 "2" 2 "3" 3 "4" 4 "5") xtitle(`:var lab rep78') ///
    vert offset(0) nokey
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	14.8 KB
ID:	1785039

    Comment


    • #3
      Hi Andrew,

      thank you for your response, much appreciated! Unfortunately, I cannot add the aggregate estimate to the coefplot, as I didn't estimate a dummy model. I just extract the coefficient of interest from 23 individual regressions and plot them together. For comparison, I want the confidence interval of another regression (the aggregate one) also in the plot, but not simply as one of the coefficients, but as a grey band over all of the coefficients. As in this picture:



      Best
      Noemi
      Attached Files

      Comment


      • #4
        That's just a shaded area, and I provided a link that shows you how to do this. If you need specific code suggestions, provide a reproducible example, e.g., modifying my example in #2 and indicating at what values you want the shaded area.

        Comment


        • #5
          Hi Andrew,

          thanks for getting back. Thank you also for the link, I'm just not sure how to apply this information to my case, at it uses twoway and not coefplot (and I'm looking for a way to do this with coefplot). So, referring to the example you provided, I would like to have a shaded area between lets say -10 and -5 over the whole x-axis. Do you have an idea how this can be done?

          Comment


          • #6
            Using twoway scatteri is one way, as shown in the linked article.

            Code:
            sysuse auto, clear
            regress mpg ib5.rep78
            
            coefplot ., drop(_cons)  ///
            ylab(-15(5)5) xlab(1 "2" 2 "3" 3 "4" 4 "5") ///
            xtitle(`:var lab rep78') vert offset(0) nokey ///
            addplot(scatteri -10 0 -10 5, recast(area) base(-5) bc(gray%40)) 

            Click image for larger version

Name:	Graph.png
Views:	1
Size:	15.2 KB
ID:	1785067

            Comment

            Working...
            X