Announcement

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

  • Creating a Combined "Coefficient + Confidence Interval" Legend Symbol with Coefplot in Stata

    I'm having trouble creating a legend symbol that combines both a coefficient marker and its confidence interval in a graph using the coefplot command in Stata, similar to what is shown in Image 1.


    Despite my attempts, I haven't been able to achieve this effect, and my current output looks like what's shown in Image 2.


    Here's the code I've been using:
    Code:
    sysuse auto, clear
    logit foreign mpg
    margins, at(mpg=(10(2)40)) post
    estimates store bivariate
    logit foreign mpg turn price
    margins, at(mpg=(10(2)40)) post
    estimates store multivariate
    coefplot ///
    (bivariate, recast(line) lcolor("0 170 250") lwidth(2.5pt) ciopts(recast(rarea) fcolor("0 170 250%40") lcolor(%0))) ///
    (multivariate, recast(line) lcolor("200 100 0") lwidth(2.5pt) ciopts(recast(rarea) fcolor("200 100 0%40") lcolor(%0))), ///
    graphr(c(white)) ///
    xtitle(Mod) xscale(off) ///
    at lwidth(*2) ///
    legend(ring(0) pos(11) si(12pt) cols(1) rowgap(1pt) colgap(0pt) region(ls(none)) symy(4pt) symx(6pt))
    Could anyone offer some guidance on how to generate a legend symbol that visually represents both the coefficient and its confidence interval, as intended? Any help would be greatly appreciated.

  • #2
    I've never figured out how marginsplot does it. You probably have to program the legend manually. Note that coefplot is from SSC (FAQ Advice #12).

    Code:
    sysuse auto, clear
    logit foreign mpg
    margins, at(mpg=(10(2)40)) post
    estimates store bivariate
    logit foreign mpg turn price
    margins, at(mpg=(10(2)40)) post
    estimates store multivariate
    coefplot ///
    (bivariate, recast(line) lcolor("0 170 250") lwidth(2.5pt) ciopts(recast(rarea) fcolor("0 170 250%40") lcolor(%0))) ///
    (multivariate, recast(line) lcolor("200 100 0") lwidth(2.5pt) ciopts(recast(rarea) fcolor("200 100 0%40") lcolor(%0))), ///
    addplot((scatteri 1.1 10 1.1 12, recast(line) lcolor("0 170 250") lw(thick)) ///
    (scatteri 1.1 12.5 (3) "Whatever 1", mc(none) mlabc(black) mlabsize(medlarge)) ///
    (scatteri 1.1 10 1.1 12, recast(line) lw(8) lcolor("0 170 250%40"))  ///
    (scatteri 0.98 10 0.98 12, recast(line) lcolor("200 100 0") lw(thick)) ///
    (scatteri 0.98 12.5 (3) "Whatever 2", mc(none) mlabc(black) mlabsize(medlarge)) ///
    (scatteri 0.98 10 0.98 12, recast(line) lw(8) lcolor("200 100 0%40") ) ) ///
    graphr(c(white)) ///
    xtitle(Mod) xscale(off) ///
    at lwidth(*2) ///
    legend(off)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	48.8 KB
ID:	1742571

    Last edited by Andrew Musau; 08 Feb 2024, 14:08.

    Comment


    • #3
      Thanks for guidanceļ¼

      Comment

      Working...
      X