Announcement

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

  • Graph Bar -> adding a "total" bar automatically, without generating a new category

    Dear all, I would like to add a "total" bar within my bar chart

    There are two variables - and five different categories.

    Now i would like to obtain - without creating another category - the total over all categories, so I can compare the variables directly in my bar chart.

    Is there any option I can add in my code?

    Thank you for any hints!

    graph bar (median) a_t w_t if sex==1,
    over(erwst_paar, relabel(1 "a" 2 "b" 3 "c" 4 "d" 5 "e") )
    ytitle("Stunden (Median)")
    yscale(range(0/50))
    ylabel(0(5)50, labsize(small))
    legend(position(6) label(1 "actual time") label(2 "wanted time")
    size(vsmall) cols(3) colfirst )

  • #2
    But what do you want the "total" to show? The total of the medians? The median across all categories?

    There aren't trivial short-cuts here usually. http://www.stata-journal.com/article...article=gr0058 is relevant if you have access.

    Comment


    • #3
      I still don't understand your definitions. Medians aren't inherently additive. Perhaps this is equivalent.

      Code:
       
      sysuse auto, clear
      graph bar (median) turn trunk , over(rep78)
      egen total_turn = total(turn), by(rep78)
      egen total_trunk = total(trunk), by(rep78)
      graph bar (median) turn total_turn trunk total_trunk, over(rep78)

      Comment


      • #4
        Then the equivalent is

        Code:
        sysuse auto, clear
        graph bar (median) turn trunk , over(rep78)
        egen median1 = median(turn)
        egen median2 = median(trunk) 
        graph bar (median) turn trunk median1 median2, over(rep78)

        Comment


        • #5
          Dear Nick, thank you very much for your help, this is very much appreciated. Kind regards, Louisa

          Comment


          • #6
            Hi, I have the same problem of Louisa but, following the Nick advise, Stata returns this error:

            may not specify more than two by variables when a varlist is specified
            r(198)

            any idea?

            Comment


            • #7
              Originally posted by Nick Cox View Post
              Then the equivalent is

              Code:
              sysuse auto, clear
              graph bar (median) turn trunk , over(rep78)
              egen median1 = median(turn)
              egen median2 = median(trunk)
              graph bar (median) turn trunk median1 median2, over(rep78)
              Hi, I have the same problem of Louisa but, following your advise, Stata returns this error:

              may not specify more than two by variables when a varlist is specified
              r(198)

              any idea?
              Thanks for any help.

              Comment


              • #8
                We can see my syntax but not yours.

                Comment


                • #9
                  Originally posted by Nick Cox View Post
                  We can see my syntax but not yours.
                  My code is:

                  egen minpergame_mean = mean(MinPerGame), by(tourney_name season)
                  graph hbar (mean) MinPerGame minpergame_mean if AudPres2020 == "NO AUDIENCE", over(season) over(tourney_name) over(AudPres2020)

                  where
                  MinPerGame = duration in minutes of each match
                  tourney_name = name of each tournament in the database
                  season = year of tournament
                  AudPres2020 = NO AUDIENCE --> Tournaments played in 2019 behind open doors and 2020 behind closed doors
                  AudPres2020 = PARTIAL --> Tournaments played in 2019 with open doors and 2020 with semi-open doors
                  AudPres2020 = TOTAL --> Tournaments played in 2019 open-door and 2020 open-door
                  Last edited by Gianni Carboni; 02 Nov 2021, 07:29.

                  Comment


                  • #10
                    #9 See the help. You have two outcomes and three over() options. The error message isn't very good, but your syntax is in error.

                    Up to two over()
                    options may be specified when multiple yvars are specified, and up to three over()s may be specified when one yvar is specified; options may be
                    specified; see Examples of syntax and Multiple over()s (repeating the bars) under Remarks below.

                    Comment

                    Working...
                    X