Announcement

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

  • Line break in a string variable, its posible?

    Hi all,

    I wonder if its posible a line break in a string variable, my idea is use this variable in a tabplot graph, example:

    Code:
    
    
                   clear
                   input byte(a1 b1 c1)
                   2 1 2
                   1 2 1
                   2 2 2
                   2 2 1
                   2 2 2
                   2 1 1
                   1 2 2
                   3 3 3
                   2 2 2
                   2 2 1
                   1 2 2
                   1 1 1
                   3 3 3
                   3 3 3
                   3 3 3
                   3 3 3
                   1 1 2
                   2 1 1
                   2 1 2
                   3 3 3
                   1 2 2
                   2 2 1
                   1 1 2
                   1 1 1
                   1 2 2
                   2 2 1
                   1 2 2
                   1 2 1
                   1 2 2
                   2 2 1
                   end
                   label values a1 size
                   label values b1 size
                   label values c1 size
                   label def size 1 "big", modify
                   label def size 2 "small", modify
                   label def size 3 "medium", modify
    
                   rename (a1 b1 c1) (size=)
                   gen long id = _n
                   reshape long size, i(id) j(which) string
    
                   bysort which size : gen freq = _N
                   by which : gen pc = 100 * freq / _N
                   gen show = "   " + string(freq) + " (" + string(pc, "%2.1f") + "%" +")"
    
    tabplot size, by(which, col(1) compact note("")) ///
    showval(show, offset(0.18)) ///
    subtitle(, pos(9) nobox nobexpand fcolor(none)) ///
    xtitle("") ytitle("") horizontal
    The output is:
    Click image for larger version

Name:	1.png
Views:	2
Size:	12.2 KB
ID:	1540531




    I wonder if its posible get (I use a photo editor to get it):
    Click image for larger version

Name:	2.png
Views:	1
Size:	19.6 KB
ID:	1540532



    I did try with splitvallabels but not success:

    Code:
    ssc install splitvallabels
    
    encode  show, gen(alt)
    splitvallabels alt , length(9)        
    
    tabplot size, by(which, col(1) compact note("")) ///
    showval(`(rlabel)', offset(0.18)) ///
    subtitle(, pos(9) nobox nobexpand fcolor(none)) ///
    xtitle("") ytitle("") horizontal
    output:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	22.7 KB
ID:	1540535



    Thanks in advance
    Rodrigo
    Last edited by Rodrigo Badilla; 09 Mar 2020, 18:19.

  • #2
    You can get close with subscripts and superscripts, but the alignment will not be what you want.

    Code:
    gen show2 = "{sub:"+" (" + string(pc, "%2.1f")+ ")"+"}{sup:"+ string(freq)+ "}"
    tabplot size, by(which, col(1) compact note("")) ///
    showval(show2, offset(0.18) mlabsize(large)) ///
    subtitle(, pos(9) nobox nobexpand fcolor(none)) ///
    xtitle("") ytitle("") horizontal
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	46.2 KB
ID:	1540540

    Comment


    • #3
      Thanks Andrew Musau its a good aproach, I will check the details...

      Comment

      Working...
      X