Announcement

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

  • Format numbers using coefplot with no leading zeros or scientific notation

    I am trying to create a coefficient plot with marker labels using the coefplot command. I want all of the numbers in the graph to not have leading zeros and not use scientific. If I use the %#.#f format there is a leading zero, but if I use the %#.#g format it turns small numbers into scientific notation (all of my all of my coefficients are between 1 and -1). Is there a way to do this?

    Here is my code:

    coefplot (elections_td, label("Approve of Trump")) (elections_ta, label("Disapprove of Trump")) ///
    , bylabel("Support for Elections") || ///
    freespeech_td freespeech_ta, bylabel("Support for Free Speech") || ///
    equality_td equality_ta, bylabel("Support for Equality") || ///
    minorities_td minorities_ta, bylabel("Support for Tolerance") || ///
    , xsize() ysize(3) aspect() subtitle(, bcolor(white) size(medsmall)) ///
    plotr(lstyle(none) lw(vthick) color(gs14)) xline(0, lpat(longdash) lcolor(gs7)) msize(small) ///
    coeflabels(, labsize(small) wrap(10)) xlabel(-.8(.4).8, labsize(small)) ///
    levels(95) ciopts(recast(rcap)) mlabel mlabposition(12) format(%1.0g) ///
    mlabgap(*2) drop(_cons male nonwhite age) ///
    legend(region(lstyle(none)) size()) byopts(graphregion(color(white)) rows(1) scale(1.2))

    Thanks so much!

  • #2
    coefplot is from SSC (FAQ Advice #12). Being your first post, I will overlook the lack of a data example. For your future posts, see the referenced FAQ Advice on how to present data examples using the dataex command.

    Code:
    sysuse auto, clear
    replace price= price/1e+5
    regress price mpg weight, nocons
    set scheme s1mono
    coefplot, mlabel format("%7.6f") mlabpos(1) saving(gr1, replace)
    coefplot, mlabel(cond(substr(string(@b,"%7.6f"), 1, 1)=="-", "-"+ ///
    substr(string(@b,"%7.6f"), 3, .),  substr(string(@b,"%7.6f"), 2, .) )) ///
    mlabpos(1) saving(gr2, replace)
    gr combine gr1.gph gr2.gph
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	28.3 KB
ID:	1674225

    Comment

    Working...
    X