Announcement

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

  • Is there a way to use midline decimals instead of regular decimals when plotting coefficients and 95% CI?

    Hi all,

    A journal that I am planning to submit a paper requires to use decimal points midline (ie, 10·1) instead of regular decimal points (ie 10.1) when presenting results graphically. Is there a way to achieve that purpose when using twoway or coefplot command (from ssc)? I have tried to use graph editor but it seems there is no option to change the format of point estimates. For your reference, to create a midline decimal on a PC: hold down ALT key and type 0183 on
    the number pad, or on a Mac: shift + option + 9.

    Here is a data example and code written by Andrew Musau: https://www.statalist.org/forums/for...ic-regressions
    Thank you.
    Code:
        sysuse auto, clear
        set seed 02032022
        
        gen depvar= runiformint(0,1)
            lab def record  0 "zero" 1 "one" 2 "two" 3 "three" 4 "four" 5 "five"
            lab val rep78 record
            
        gen mpglev = 1 + (mpg >= 20) + (mpg>=25) if !mi(mpg)
            lab define mpglevels 1 "High mileage" 2 "Average" 3 "Economical"
            lab values mpglev mpglevels
            
        logit depvar i.rep78 i.mpglev i.foreign, or nolog
        est sto m1
    
    * Selec x-axis position to set the marker labels 
        gen xpos = 45
    
    * Graph
        coefplot (m1,  keep(*.rep78) aseq(Repair record)\ m1, keep(*.mpglev) aseq(Mileage) /// 
                 \ m1, keep(*.foreign) aseq(Origin)), /// 
                 drop(_cons) scheme(white_tableau) /// 
                 mlabel(cond(@b==1, "", string(@b,"%9.3f") + "   " +"["+string(@ll,"%9.3f") + /// 
                 " " +string(@ul,"%9.3f")+ "]" )) baselevels mlabcolor(none) mcolor(blue) /// 
                 ciopts(lcolor(blue)) eform xline(1) xsc(r(-5 65)) addplot(scatter @at xpos, /// 
                 ms(i) mlab(@mlbl) mlabcolor(black) mlabgap(3) mlabsize(small)) graphr(margin(r=10))

  • #2
    One way is to specify separately what precedes the decimal point and what comes after. I do this for the coefficients below (highlighted).

    Code:
    sysuse auto, clear
        set seed 02032022
        
        gen depvar= runiformint(0,1)
            lab def record  0 "zero" 1 "one" 2 "two" 3 "three" 4 "four" 5 "five"
            lab val rep78 record
            
        gen mpglev = 1 + (mpg >= 20) + (mpg>=25) if !mi(mpg)
            lab define mpglevels 1 "High mileage" 2 "Average" 3 "Economical"
            lab values mpglev mpglevels
            
        logit depvar i.rep78 i.mpglev i.foreign, or nolog
        est sto m1
    
    * Selec x-axis position to set the marker labels
        gen xpos = 45
    
    * Graph
        coefplot (m1,  keep(*.rep78) aseq(Repair record)\ m1, keep(*.mpglev) aseq(Mileage) ///
                 \ m1, keep(*.foreign) aseq(Origin)), drop(_cons) ///
                 mlabel(cond(@b==1, "", string(int(@b),"%9.0f") + "·" +string((@b*1e+4-(int(@b)*1e+4))/10, "%3.0f")+ ///
                 "   " +"["+string(@ll,"%9.3f") + ///
                 " " +string(@ul,"%9.3f")+ "]" )) baselevels mlabcolor(none) mcolor(blue) ///
                 ciopts(lcolor(blue)) eform xline(1) xsc(r(-5 65)) addplot(scatter @at xpos, ///
                 ms(i) mlab(@mlbl) mlabcolor(black) mlabgap(3) mlabsize(small)) graphr(margin(r=10))
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	37.0 KB
ID:	1761334

    Last edited by Andrew Musau; 11 Aug 2024, 19:20.

    Comment


    • #3
      Even better:

      Code:
          coefplot (m1,  keep(*.rep78) aseq(Repair record)\ m1, keep(*.mpglev) aseq(Mileage) ///
                   \ m1, keep(*.foreign) aseq(Origin)), drop(_cons)  ///
                   mlabel(cond(@b==1, "", subinstr(string(@b,"%9.3f"), ".", "·", 1) ///
                   + "   " +"["+string(@ll,"%9.3f") + ///
                   " " +string(@ul,"%9.3f")+ "]" )) baselevels mlabcolor(none) mcolor(blue) ///
                   ciopts(lcolor(blue)) eform xline(1) xsc(r(-5 65)) addplot(scatter @at xpos, ///
                   ms(i) mlab(@mlbl) mlabcolor(black) mlabgap(3) mlabsize(small)) graphr(margin(r=10))
      to avoid problems with decimals of the form "x.999y" where \(x, y\in\mathbb{R}\).

      Comment


      • #4
        Thank you so much for your wonderful help as always, Andrew Musau.

        Comment


        • #5
          I am impressed both by the 'technical' and 'cultural' ramifications of the 'midline decimal point', just read the discussion here at the Academia Exchange.
          But, notwithstanding the solution that Andrew provides, would it not be most easy to have a standard option in Stata as such - to select the 'midline decimal point' as a (third) decimal option - as it is a so easy to implement technical solution to just be able to use the 'middle dot' character (ALT key and type 0183 on the number pad).
          http://publicationslist.org/eric.melse

          Comment

          Working...
          X