Announcement

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

  • Drawing a bar graph with 3 variables

    Dear Stata users, Hello;

    I do have this data in hand:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int anne long(carburantendt picesderechangesendt totalendt)
    2010 5905854 3493348  9399202
    2011 6312541 1907192  8219733
    2012 6428169 1539269  7967438
    2013 6854515 1389149  8243664
    2014 7000057 1327483  8327540
    2015 6658717 1416395  8075112
    2016 6253594 1264704  7518298
    2017 5845295 1997840  7843135
    2018 6384211 2960611  9344822
    2019 7866141 2227585 10093726
    2020 5291235 1781410  7072645
    end
    format %ty anne
    The first variable "anne" is a time variable that is already set with the "tsset" command.
    I would love to draw a time bar-graph which shows the evolution of the other 3 financial variables according to the time variable "anne", all in the same graph, I would love if the bar of each financial variable has a different color and is spaced from the other bar (like, I want all the bars to start from 0).

    Any help, please?

    With thanks!

  • #2
    That can be done. Whether it's the best display for such data is a different question. Many researchers would prefer a line chart and then not feel obliged to show zero.

    Also, since it appears that carb + pices = total, that raises other possibilities.

    I'm guessing currency, but if the units are different, the same need arises to explain them.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int anne long(carburantendt picesderechangesendt totalendt)
    2010 5905854 3493348  9399202
    2011 6312541 1907192  8219733
    2012 6428169 1539269  7967438
    2013 6854515 1389149  8243664
    2014 7000057 1327483  8327540
    2015 6658717 1416395  8075112
    2016 6253594 1264704  7518298
    2017 5845295 1997840  7843135
    2018 6384211 2960611  9344822
    2019 7866141 2227585 10093726
    2020 5291235 1781410  7072645
    end
    format %ty anne
    
    forval x = 1/10 {
        local call `call' `x'e6 "`x'"
    }
    
    graph bar (asis) carburantendt picesderechangesendt totalendt, over(anne) legend(row(1) pos(12)) ///
    yla(0 `call') ytitle(explain currency units here: million whatever)
    Click image for larger version

Name:	bad_bar_chart.png
Views:	1
Size:	52.2 KB
ID:	1745439


    Last edited by Nick Cox; 04 Mar 2024, 05:10.

    Comment


    • #3
      Nick Cox Hi, and Thanks for the help;

      Yes indeed, the three financial indicators have the same monetary unit, yet I wanted to have the financial values on the y axis, not like 0, 1, 2, 3, ...
      I guess a bar graph is also a good representation to knw which the levels of each financial indicator between the three.

      Thanks for the help.

      Comment


      • #4
        As already indicated, the numbers are explained in my axis title as being in millions. If you really do want to see numbers like 8e6 (which would be the default here) or even 8000000, then change the code to suit.

        Comment


        • #5
          Nick Cox I understand.

          Thanks very much for the help.

          Comment


          • #6
            Nick Cox The problem is that, when using that data and that code to draw the graph, I still get the values of those financial indicators on the graph in their scientific format. Is there a way to get rid of that format on the graph and to have those values one the graph as they are on the dataset please?

            Comment


            • #7
              Code:
              help axis label options
              explains. You can specify any numeric format to over-ride the default with a format() suboption.

              I've got to say that repeated zeros in values such as 0 2000000 4000000 6000000 8000000 10000000 -- even with extra commas -- would not be likely to impress anyone numerate who might review your work. Wouldn't "millions" be clearer for academic readers (and CEOs, politicians and children too)? (If I recall correctly, it's the same in French as in English.)

              Comment


              • #8
                Nick Cox I understand. Thanks for the help.

                Comment


                • #9
                  Code:
                  graph bar (asis) carburantendt picesderechangesendt totalendt, over(anne) legend(row(1) pos(12)) ///
                  yla(0(2e6)10e6, format(%9.0f)) ytitle(explain currency units here)
                  would be one way to get labels 0(2000000)10000000 should someone insist on that.

                  Comment

                  Working...
                  X