Announcement

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

  • coefplot: Add a line break to coefficient labels

    I have a lot of coefficients which have long labels, so for layout purposes it would be good to be able to add line breaks. It is complicated a bit by the fact that I am using aseq and swapnames, because I am visualizing the effect of 1 independent variable on many different dependent variables.

    With the autodata, this is what I want to acheive: That the label on the left side "Miles per gallon" has a line break, after 'Miles', i.e., it appears as:
    Miles
    per gallon

    Code:
    sysuse auto, clear
    reg price trunk
    estimates store price
    reg mpg trunk
    estimates store mpg
    reg headroom trunk
    estimates store headroom
    
    coefplot ///
        (price, aseq(Price)) ///
        (mpg, aseq(Miles per gallon)) ///
        (headroom, aseq(Headroom (in.))) ///
        , keep(*trunk) swapnames legend(off)
    Thanks!

  • #2
    You may try adding ASCII characters 10 and/or 13, although this is not a documented method of introducing a line-break.

    Code:
    sysuse auto, clear
    reg price trunk
    estimates store price
    reg mpg trunk
    estimates store mpg
    reg headroom trunk
    estimates store headroom
    
    set scheme s1mono
    coefplot ///
        (price, aseq(Price)) ///
        (mpg, aseq(Miles`=char(13)'`=char(10)'per gallon)) ///
        (headroom, aseq(Headroom (in.))) ///
        , keep(*trunk) swapnames legend(off)
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	15.3 KB
ID:	1713251

    Comment


    • #3
      Thank you Andrew Musau . I hope I can ask one more question? How can I change the font size of the labels?

      Comment


      • #4
        Code:
        sysuse auto, clear
        reg price trunk
        estimates store price
        reg mpg trunk
        estimates store mpg
        reg headroom trunk
        estimates store headroom
        
        set scheme s1mono
        coefplot ///
            (price, aseq(Price)) ///
            (mpg, aseq(Miles`=char(13)'`=char(10)'per gallon)) ///
            (headroom, aseq(Headroom (in.))) ///
            , keep(*trunk) swapnames legend(off) ylab(,labsize(vsmall))

        Comment


        • #5
          Thanks so much Andrew Musau ! One final question if you would: In my real data, the labels where I make line breaks are fairly long, meaning that after the line break, there i a quite large white area in the left side of the graph. Are there any way which I can instruct -coefplot to make the "data area" wider, so the labels are almost meeting the left border of the graph.

          Comment


          • #6
            I do not know. Maybe show an example.

            Comment


            • #7
              Originally posted by Andrew Musau View Post
              I do not know. Maybe show an example.
              The problem is, that the "data area" is as wide with the linebreak as it is without the linebreak. It seems Stata adjusts the with based on the number of characters. What I want is a width as in the first graph:

              Code:
              sysuse auto, clear
              reg price trunk
              estimates store price
              reg mpg trunk
              estimates store mpg
              reg headroom trunk
              estimates store headroom
              
              *short label, desired "data area" width
              set scheme s1mono
              coefplot ///
                  (price, aseq(Price)) ///
                  (mpg, aseq(Miles pr. gallon)) ///
                  (headroom, aseq(Headroom (in.))) ///
                  , keep(*trunk) swapnames legend(off) ylab(,labsize(vsmall))
              
              *without linebreak
              set scheme s1mono
              coefplot ///
                  (price, aseq(Price)) ///
                  (mpg, aseq(Correlation between miles per gallon and trunk space)) ///
                  (headroom, aseq(Headroom (in.))) ///
                  , keep(*trunk) swapnames legend(off) ylab(,labsize(vsmall))
              
              *with linebreak
              set scheme s1mono
              coefplot ///
                  (price, aseq(Price)) ///
                  (mpg, aseq(Correlation between`=char(13)'`=char(10)' miles per gallon `=char(13)'`=char(10)'and trunk space)) ///
                  (headroom, aseq(Headroom (in.))) ///
                  , keep(*trunk) swapnames legend(off) ylab(,labsize(vsmall))

              Comment


              • #8
                You can force a negative outer gap.

                Code:
                sysuse auto, clear
                reg price trunk
                estimates store price
                reg mpg trunk
                estimates store mpg
                reg headroom trunk
                estimates store headroom
                
                *short label, desired "data area" width
                set scheme s1mono
                coefplot ///
                    (price, aseq(Price)) ///
                    (mpg, aseq(Miles pr. gallon)) ///
                    (headroom, aseq(Headroom (in.))) ///
                    , keep(*trunk) swapnames legend(off) ylab(,labsize(vsmall))
                
                *without linebreak
                set scheme s1mono
                coefplot ///
                    (price, aseq(Price)) ///
                    (mpg, aseq(Correlation between miles per gallon and trunk space)) ///
                    (headroom, aseq(Headroom (in.))) ///
                    , keep(*trunk) swapnames legend(off) ylab(,labsize(vsmall))
                
                *with linebreak
                set scheme s1mono
                coefplot ///
                    (price, aseq(Price)) ///
                    (mpg, aseq(Correlation between`=char(13)'`=char(10)' miles per gallon `=char(13)'`=char(10)'and trunk space)) ///
                    (headroom, aseq(Headroom (in.))) ///
                    , keep(*trunk) swapnames legend(off) ylab(,labsize(vsmall)) ysc(outergap(-40))
                Click image for larger version

Name:	Graph.png
Views:	1
Size:	14.3 KB
ID:	1713288

                Comment


                • #9
                  Andrew Musau perfect, thanks for your kind help!

                  Comment

                  Working...
                  X