Announcement

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

  • Line break in an automatic twoway, by(x1 x2) subtitle?

    Hi

    I have the following situation:


    Click image for larger version

Name:	Screenshot 2024-03-13 190534.png
Views:	1
Size:	47.8 KB
ID:	1746565


    To reproduce the problem:

    Code:
    clear
    input x1 x2 x3 y
    0 0 0 2
    0 0 1 5
    0 1 0 7
    0 1 1 3
    1 0 0 9
    1 0 1 4
    1 1 0 2
    1 1 1 4
    end
    
    label define x 0 "very long word" 1 "much longer word"
    label val x1 x2 x3 x
    
    twoway bar y x1, by(x2 x3, row(1) note(""))
    I am unhappy with the way Stata handles the value labels of the x2 and x3 variables. Is there any way to change this? I figured out that I can probably change the font size, but ideal would be a line break instead of the comma that Stata automatically added. Is there such an option?

    Thanks so much for your consideration
    KS

  • #2
    You can try inserting char(10) or char(13), but be careful as this might generate unwanted behavior elsewhere:

    Code:
    clear
    input x1 x2 x3 y
    0 0 0 2
    0 0 1 5
    0 1 0 7
    0 1 1 3
    1 0 0 9
    1 0 1 4
    1 1 0 2
    1 1 1 4
    end
    
    label define x 0 "very `=char(13)' long `=char(13)' word" 1 "much `=char(13)' longer `=char(13)' word"
    label val x1 x2 x3 x
    
    twoway bar y x1, by(x2 x3, row(1) note(""))
    Attached Files

    Comment


    • #3
      If you try the three solutions below, you may find that at least the horizontal solutions accommodate your real value labels well.


      Code:
      clear
      input x1 x2 x3 y
      0 0 0 2
      0 0 1 5
      0 1 0 7
      0 1 1 3
      1 0 0 9
      1 0 1 4
      1 1 0 2
      1 1 1 4
      end
      
      graph bar (asis) y, over(x1) over(x2) by(x3)
      
      graph hbar (asis) y, over(x1) over(x2) by(x3)
      
      graph dot (asis) y, over(x1) over(x2) by(x3)

      Comment


      • #4
        Thank you both!

        Comment

        Working...
        X