Announcement

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

  • Two variables in one histogram graph in Stata

    Dear All,

    Hope you are fine.

    Could you please help me to create an histogram of two variables (M0 and M01) in the same graph (in the horizontal axis we find H1, H2,......H11) and in the vertical axis we find values of two variables M0 and M01).

    Please find attached.

    Thanks in advance,
    N.K
    Attached Files

  • #2
    Your MS Word attachment (deprecated here: please read #12 of FAQ Advice) is just a list of data. It needs surgery before anything useful can be made of it in Stata.

    https://www.statalist.org/forums/help#stata is there for a purpose: to help you help others to get good, fast answers. Please read and act on it.

    I can't see that any kind of histogram applies here usefully. Perhaps you mean a bar chart, but a dot chart would in my view work much better still.

    Here is some technique.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str13 categ float(M0 M01)
    "H1"        3.8  3.8
    "H2"        5.1  5.2
    "H3"        9.2 11.6
    "H4"          5  5.1
    "H5"        7.8   11
    "H6"       13.1 18.9
    "H7"       16.8 20.6
    "H8"       20.7 28.9
    "H9"       21.5 26.8
    "H10"       8.9  6.6
    "H11"      20.9 17.7
    "National" 13.2 14.5
    end
    
    
    separate M0, by(categ == "National") gen(M0_)
    separate M01, by(categ == "National")  gen(M01_)
    
    graph dot (asis) M0_? M01_? , over(categ, label(labsize(small)) sort(M0)) ///
    marker(1, ms(Oh) mc(red)) marker(2, ms(O) mc(red))  /// 
    marker(3, ms(Th) mc(blue)) marker(4, ms(T) mc(blue)) ///
    legend(order(3 "M01" 1 "M0") pos(9) col(1))         ///
    scheme(s1color) vertical yla(, ang(h)) ///
    linetype(line) lines(lc(gs12) lw(vthin)) ysc(titlegap(0))

    Click image for larger version

Name:	dot_not_bar.png
Views:	1
Size:	26.1 KB
ID:	1546331




    .


    Comment


    • #3
      Thanks a lot Nick! it is helpful.

      N.K

      Comment


      • #4
        Dear Nick,

        Thank you for your help. I have another question please. I used the graph bar command but I had the following graphics where the Y-axis is not clear.

        I used the command:

        graph hbar M0 M01, over(categ, sort(order)) blabel(bar, position(inside))

        Thanks,
        Click image for larger version

Name:	graphics.png
Views:	1
Size:	21.2 KB
ID:	1550505

        Last edited by naceur habib; 01 May 2020, 10:28.

        Comment


        • #5
          That doesn't correspond to any data example so far visible in the thread.

          Comment


          • #6
            Thanks a lot Nick. This is the data that I have used. Many Thanks
            H M0 categ H1 M01 order
            4.9 3.8 Cad et prof libérales sup 6.2 5 2
            6.2 5.1 Cad et prof libérales moy 8.8 7.2 3
            11.2 9.2 Autres employés 13.4 11.4 4
            6.3 5 Pat des petits mét dans l'Ind 8.6 7 5
            9.6 7.8 Art et indép des petits mét 12.7 10.5 6
            15.6 13.1 Ouvriers non agricoles 17.9 15.7 7
            20.1 16.8 Exploitants agricoles 22.4 19.6 8
            24 20.7 Ouvriers agricoles 26.2 23.4 9
            25.5 21.5 Chômeurs 27.1 24.3 10
            8.2 6.6 Retraités 12.6 10.4 11
            21.1 17.7 Autres inactifs 28.1 24 12
            16 13.2 National 18.2 15.6 1

            Comment


            • #7
              Please use dataex as in #2 and FAQ Advice #12.

              Comment

              Working...
              X