Announcement

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

  • Stacked bar graph per groups

    Dear all,

    I would like to realize a stacked graph bar showing the different values of each category of my variable of interest.

    I provide you some fictious data that resemble mine:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float cumu byte n
    17.357025 1
     27.18098 2
      29.4684 3
      29.8549 4
    end
    I tried the following:

    tw (bar cumu n if n == 1) (bar cumu n if n == 3) (bar cumu n if n == 2) (bar cumu n if n == 1)

    but then I obtain 4 different bars (instead of stacked one).

    Do you have any suggestion?

    Thanks a lot, best, G

  • #2
    Code:
    help graph bar

    Comment


    • #3
      I believe this is what you want:
      Code:
      graph bar cumu, asyvars stack over(n)
      Red Owl
      Stata/IC 16.0 (Windows 10, 64-bit)

      Note: Crossed with #2

      Comment


      • #4
        Dear Red and Nix,

        thanks for your suggestions. Red, your syntax is what I would need, but on the Y I would like to obtain not the percentage but the absolute value (in this case 29.8). Is there any option in this sense?

        Thanks a lot, G

        Comment


        • #5
          Just add -per- as an option:
          Code:
          graph bar cumu, per asyvars stack over(n)
          Red Owl
          Stata/IC 16.0 (Windows 10, 64-bit)

          Comment


          • #6
            Dear Red, with per as option the graph still shows the percentage (and not the absolute values) on the Y axis. Did I make something wrong?

            Comment


            • #7
              Ok, probably I solved, I have to build the graph with the frequency associated to each category (and not the cumulative one).

              Thanks a lot, best, G

              Comment

              Working...
              X