Announcement

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

  • COEFPLOT, MLABEL(): Line break appears on PNG but not PDF

    Hello all,
    I am using COEFPLOT and trying to add a line break to the marker label. Specifically, at each marker, I am adding a text like `coef (se)' with a line break between coef and (se). It works great on the graph window and also in the exported PNG, but somehow the line break disappears in the exported PDF. The following code replicates the issue (at least in my environment). Any idea how to make the line break work in the PDF just like it does in PNG?

    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . reg price
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(0, 73)        =      0.00
           Model |           0         0           .   Prob > F        =         .
        Residual |   635065396        73  8699525.97   R-squared       =    0.0000
    -------------+----------------------------------   Adj R-squared   =    0.0000
           Total |   635065396        73  8699525.97   Root MSE        =    2949.5
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _cons |   6165.257   342.8719    17.98   0.000     5481.914      6848.6
    ------------------------------------------------------------------------------
    
    . coefplot, vert mlabel(string(@b,"%9.2f") + char(13) + char(10) + "(" + string(@se,"%9.2f") + ")")
    
    . gr export "reg_price.png", replace
    (file reg_price.png written in PNG format)
    
    . gr export "reg_price.pdf", replace
    (file reg_price.pdf written in PDF format)
    Click image for larger version

Name:	reg_price.png
Views:	1
Size:	32.3 KB
ID:	1636840
    reg_price.pdf
    Attached Files
    Last edited by Masaru Nagashima; 16 Nov 2021, 17:01.

  • #2
    Any thoughts, anyone...? BTW sorry for the pdf link that doesn't appear to work. I hope everyone can replicate the issue.

    Comment


    • #3
      I think you will want to convert from ps to PDF (or image to PDF). For a converter, see https://web.mit.edu/ghostscript/www/Ps2pdf.htm. There does not appear to be much evidence that anyone knew how to include a line break in a marker label prior to your post. See, e.g., https://www.statalist.org/forums/for...ariable-labels.

      Comment


      • #4
        As you want your standard errors directly underneath your coefficients, a coefplot (SSC) workaround is possible. Here is an example:

        Code:
        sysuse auto, clear
        reg price weight mpg turn, nocons
        est sto D
        coefplot (D, mlabel(string(@b,"%9.2f")) mlabc(blue) mlabpos(3)) ///
        (D, mlabel("(" +string(@se,"%9.2f") + ")") mlabc(blue) mlabpos(5) ///
        mlabgap(0.05in) offset(0)), vert nokey ciopts(lc(blue)) mc(blue) scheme(s1color)
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	43.2 KB
ID:	1637236



        This should export fine in PDF format.
        Last edited by Andrew Musau; 19 Nov 2021, 08:25.

        Comment


        • #5
          Dear Andrew Musau,
          Thank you for your posts. The second one, the COEFPLOT workaround, appears pretty clever. Basically you are plotting markers and their labels twice, first the coefficient values and second parentheses and the standard errors, with a slight adjustment in their positions and colours, right? I have slightly modified your code to my match taste, but this is awesome. Thank you so much!

          Code:
          . sysuse auto
          (1978 Automobile Data)
          
          . reg price
          
                Source |       SS           df       MS      Number of obs   =        74
          -------------+----------------------------------   F(0, 73)        =      0.00
                 Model |           0         0           .   Prob > F        =         .
              Residual |   635065396        73  8699525.97   R-squared       =    0.0000
          -------------+----------------------------------   Adj R-squared   =    0.0000
                 Total |   635065396        73  8699525.97   Root MSE        =    2949.5
          
          ------------------------------------------------------------------------------
                 price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
          -------------+----------------------------------------------------------------
                 _cons |   6165.257   342.8719    17.98   0.000     5481.914      6848.6
          ------------------------------------------------------------------------------
          
          . coefplot (, mlabel(string(@b,"%9.2f")) mlabpos(3) mc(navy)) (, m(none) mlabel("(" + string(@se,"%9.2f") + ")") mlabc(navy) mlabpos(5) offset(0) noci), vert nokey
          
          . gr export reg_price_update.png, replace
          (file reg_price_update.png written in PNG format)
          
          . gr export reg_price_update.pdf, replace
          (file reg_price_update.pdf written in PDF format)
          
          .
          reg_price_update.pdf
          Click image for larger version

Name:	reg_price_update.png
Views:	1
Size:	17.2 KB
ID:	1637885

          Comment


          • #6
            Basically you are plotting markers and their labels twice, first the coefficient values and second parentheses and the standard errors, with a slight adjustment in their positions and colours, right?
            Yes. Adding the option -noci- to the second plot as you do is a better approach as you only need to match the color of the labels.

            Comment

            Working...
            X