Announcement

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

  • #16
    As a footnote to Andrew Musau's excellent answer here is an example of tabplot in action.

    As flagged in https://www.statalist.org/forums/for...ories-per-cell the design idea goes back at least to Charles Booth in 1889.

    tabplot can appeal if you prefer

    * to lose a legend as being at best a necessary evil

    * a clearer distinction between outcome and control

    * a hybrid of graph and table (which Andrew's design also offers).

    Colours are allowed too; this particular choice is offered on a day when I lean to Bauhaus-Shaker-Tufte minimalism. The latter may be forced on you if you publish in a place where multiple colours are not allowed or far too expensive.

    Click image for larger version

Name:	minimal.png
Views:	1
Size:	43.9 KB
ID:	1786518


    Code:
    clear
    input float(n treat1 treat2 treat3 treat4)
    1 2 2 1 .
    2 2 3 3 3
    3 2 3 3 3
    4 2 . . .
    5 2 2 2 2
    6 1 1 2 1
    7 3 3 3 3
    8 2 2 2 .
    9 2 2 2 2
    10 2 . . .
    11 2 2 1 2
    12 2 . . .
    13 2 3 3 3
    14 2 2 2 .
    15 2 . . .
    16 2 . . .
    17 2 2 3 .
    18 2 . . .
    19 2 2 2 2
    20 2 2 1 2
    21 0 0 1 .
    end
    
    reshape long treat, i(n) j(origin)
    drop if missing(treat)
    
    label values origin origin
    label def origin 1 "SUB-dose-MC", modify
    label def origin 2 "TA-MC", modify
    label def origin 3 "SUPER-dose-MC", modify
    label def origin 4 "TI-MC", modify
    
    label values treat treat
    label def treat 0 "Inconclusive", modify
    label def treat 1 "Under-treatment", modify
    label def treat 2 "Adequate", modify
    label def treat 3 "Over-treatment", modify
    
    set scheme  stcolor
    
    tabplot treat origin, percent(origin) showval subtitle(%) ///
    ytitle("") xtitle("") blcolor(black) bfcolor(none)

    Comment


    • #17
      Hello, Andrew!

      Thank you for your reply.
      However, this is still not the type of graph bar I need.
      Please see the new example below showing the layout I'm trying to achieve.
      I'd like the variables to be arranged in the graph bar as shown in the example, using the same dataset that I posted previously.

      Attached Files

      Comment


      • #18
        Sorry, but what's the difference beyond text labels?

        Comment


        • #19
          I am looking for the opposite arrangement: the outcome categories (0, 1, 2, and 3) on the x-axis, with four side-by-side bars within each category, one for each treatment percentage
          .

          Comment


          • #20
            Don't you just reverse the order of variables?

            Code:
            clear
            input float(n treat1 treat2 treat3 treat4)
            1 2 2 1 .
            2 2 3 3 3
            3 2 3 3 3
            4 2 . . .
            5 2 2 2 2
            6 1 1 2 1
            7 3 3 3 3
            8 2 2 2 .
            9 2 2 2 2
            10 2 . . .
            11 2 2 1 2
            12 2 . . .
            13 2 3 3 3
            14 2 2 2 .
            15 2 . . .
            16 2 . . .
            17 2 2 3 .
            18 2 . . .
            19 2 2 2 2
            20 2 2 1 2
            21 0 0 1 .
            end
            
            reshape long treat, i(n) j(origin)
            drop if missing(treat)
            
            label values origin origin
            label def origin 1 "SUB-dose-MC", modify
            label def origin 2 "TA-MC", modify
            label def origin 3 "SUPER-dose-MC", modify
            label def origin 4 "TI-MC", modify
            
            label values treat treat
            label def treat 0 "Inconclusive", modify
            label def treat 1 "Undertreatment", modify
            label def treat 2 "Adequate", modify
            label def treat 3 "Overtreatment", modify
            
            bys origin treat: gen percent=_N
            bys origin: replace percent=(percent/_N)*100
            set scheme  stcolor
            
            gr bar percent, over(origin, gap(10)) over(treat) asyvars ///
            leg(row(1) pos(6)) ytitle(Percent) blab(total, format(%3.0f)) ylab("")
            Click image for larger version

Name:	Graph.png
Views:	1
Size:	31.3 KB
ID:	1786527

            Comment


            • #21

              Stata flagged some errors.
              Attached Files

              Comment


              • #22
                There are problems of at least two kinds here.

                1. If scheme stcolor is not found, you are using an out-of-date version of Stata. stcolor was introduced in Stata 18; you must be using Stata 17 or earlier.
                See https://www.statalist.org/forums/help#version for advice on telling us about older versions, There is no problem beyond needing to specify a different scheme or relying on the default in your version.

                2. Otherwise I think you're executing the right kinds of commands in the wrong order. For example, the variable origin is created by the reshape and can't be used before then.

                Comment


                • #23
                  It didn't work. I updated Stata, but it's still flagging some errors. Is there another way?

                  Comment


                  • #24
                    Sorry, but no-one can help without details.

                    My guess is that the code in #20 should all work in recent versions of Stata so long as you don’t try to set scheme stcolor.

                    If your data and your code differ from #20, you need to tell us how.

                    Comment


                    • #25
                      One wild guess -- I can't do better without more information -- is that you may be confusing update and upgrade.

                      So, it seems that you are running Stata 17, or an earlier version. Updating your version is not an upgrade: in particular, to use scheme stcolor you need to upgrade, which means installing a later version than that current on your machine.

                      I don't know if anyone is selling Stata 18 licences now, so you would need Stata 19.

                      But as said, that is to me the only obvious reason why Andrew Musau's code wouldn't work.

                      Comment

                      Working...
                      X