Announcement

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

  • coefplot

    Hi. I'm trying to create subplots using coefplot with the addition of displaying estimates and confidence interval on the yaxis. Since this option is not built-in we need to write a program to tweak how coefplot works. I'm sharing the code from the user manual here: http://repec.sowi.unibe.ch/stata/coefplot/markers.html

    Code:
    capt program drop coefplot_mlbl
    *! version 1.0.0  10jun2021  Ben Jann
    program coefplot_mlbl, sclass
        _parse comma plots 0 : 0
        syntax [, MLabel(passthru) * ]
        if `"`mlabel'"'=="" local mlabel mlabel(string(@b, "%5.2f") + " (" + string(@ll, "%5.2f") + "; " + string(@ul, "%5.2f") + ")")
        preserve
        qui coefplot `plots', `options' `mlabel' generate replace nodraw
        sreturn clear
        tempvar touse
        qui gen byte `touse' = __at<.
        mata: st_global("s(mlbl)", ///
            invtokens((strofreal(st_data(.,"__at","`touse'")) :+ " " :+ ///
            "`" :+ `"""' :+ st_sdata(.,"__mlbl","`touse'") :+ `"""' :+ "'")'))
        sreturn local plots `"`plots'"'
        sreturn local options `"`options'"'
    end
    
    capt program drop coefplot_ymlbl
    *! version 1.0.0  10jun2021  Ben Jann
    program coefplot_ymlbl
        _parse comma plots 0 : 0
        syntax [, MLabel(str asis) * ]
        _parse comma mlspec mlopts : mlabel
        local mlopts = substr(`"`mlopts'"', 2, .) // remove leading comma
        if `"`mlspec'"'!="" local mlabel mlabel(`mlspec')
        else                local mlabel
        coefplot_mlbl `plots', `options' `mlabel'
        coefplot `plots',  ///
            yaxis(1 2) yscale(alt) yscale(axis(2) alt noline) ///
            ylabel(none, axis(2)) yti("", axis(2)) ///
            ymlabel(`s(mlbl)', axis(2) notick angle(0) `mlopts') `options'
    end
     coefplot_ymlbl D F, drop(_cons) xline(0)


    However, the above program does not allow for the option 'bylabel'. I get a stata error saying "bylabel not allowed". I wanted to ask if there is a way to edit this code and include the bylabel option which is used to label subplots? I don't have experience writing programs and a bit unsure how to do that.

    Thanks in advance!
Working...
X