Announcement

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

  • Endash symbol (–) for mlabel value in coefplot

    Hello all,

    I need to that all negative values are expressed with an "endash" symbol (–) instead of an hypen (-). While I managed to do it for the x-axis labels, I also need it for the marker labels. Below an example of what I mean.

    Code:
    sysuse auto, clear
    
    eststo price_sto: reg price mpg headroom foreign
    
    local endash = ustrunescape("\u2013")
    dis "I want mlabel to be `endash'303.82 instead of -303.82 for negative values"
    
    coefplot ///
    (price_sto, mc(navy) msize(*1.5) mlabel mlabformat(%9.2f) mlabp(12) mlabc(black) ciopts(recast(rcap) lc(gs6))),  ///    
        keep(mpg)    ///
        ylabel(none) ///
        drop(_cons)
    Thank you very much!
    ​​​​​​​Stefan

  • #2
    SMCL supports minus signs (which in turn are not dashes).

    .
    Code:
     sysuse auto, clear
    
    . scatter mpg weight, subtitle(Minus signs are irrelevant to this graph but here is one {&minus} any way)

    Comment


    • #3
      Hi Nick, thanks for the answer.

      Is there a way to use the special sign instead of the default hyphen for mlabels option of coefplot?
      Plotting it manually with twoway would be lots of work in my multi-layered graph, so I would like to avoid it.

      Also, apologies but my example above was incomplete. Here an example how I can use an endash local for x-axis labels:

      Code:
      sysuse auto, clear
      
      eststo price_sto: reg price mpg headroom foreign
      
      local endash = ustrunescape("\u2013")
      dis "I want mlabel to be `endash'303.82 instead of -303.82 for negative values"
      
      coefplot ///
      (price_sto, mc(navy) msize(*1.5) mlabel mlabformat(%9.2f) mlabp(12) mlabc(black) ciopts(recast(rcap) lc(gs6))),  ///    
          keep(mpg)    ///
          xlabel(-400 "`endash'400" -300 "`endash'300" -200 "`endash'200") ///
          ylabel(none) ///
          drop(_cons)

      Comment


      • #4
        coefplot and estout are from SSC, as you are asked to explain (FAQ Advice #12).

        Code:
        sysuse auto, clear
        
        eststo price_sto: reg price mpg headroom foreign
        
        local endash = ustrunescape("\u2013")
        dis "I want mlabel to be `endash'303.82 instead of -303.82 for negative values"
        
        set scheme s1mono
        coefplot ///
        (price_sto, mc(navy) msize(*1.5) mlab(cond(@b<0, "`=ustrunescape("\u2013")'"+ string(abs(@b)), string(@b))) mlabformat(%9.2f) mlabp(12) mlabc(black) ciopts(recast(rcap) lc(gs6))),  ///    
            keep(mpg)    ///
            xlabel(-400 "`endash'400" -300 "`endash'300" -200 "`endash'200") ///
            ylabel(none) ///
            drop(_cons)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	10.6 KB
ID:	1712754

        Comment


        • #5
          Hi Andrew,

          Thank you for your answer. You are right, apologies for failing to mention that it is from SSC.
          Your code does not work for me, it says "factor-variable and time-series operators not allowed". Also, the mlabformat specified that I only want 2 numbers after the decimal point. How do I do this when the marker label is a string?

          Again, thank you very much for the support.

          Comment


          • #6
            Your code does not work for me, it says "factor-variable and time-series operators not allowed".
            Update your installation.


            Also, the mlabformat specified that I only want 2 numbers after the decimal point.
            Code:
            mlab(cond(@b<0, "`=ustrunescape("\u2013")'"+ string(abs(@b), "%9.2f"), string(@b, "%9.2f")))

            Comment


            • #7
              Dear Andrew,

              My current update level is the most recent, 08 Mar 2023.

              Comment


              • #8
                I have the following dates, which are the most recent from SSC. So I do not know where your installations are from.

                Code:
                . which coefplot
                *! version 1.8.6  22feb2023  Ben Jann
                
                . which estout
                *! version 3.31  26apr2022  Ben Jann

                Comment


                • #9
                  Indeed, I got confused with the general stata update. After re-installing the new version of the SSC packages everything worked.

                  Thanks a lot!

                  Comment

                  Working...
                  X