Announcement

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

  • How to report tabulate results in a bar graph?

    I'm having trouble representing the results of a -tabulate- into -graph bar-

    For example

    -tabulate NEET residency

    NEET | urban rural informal | Total
    ---------+---------------------------------+----------
    0 | 2,135 3,721 611 | 6,467
    1 | 1,179 2,782 488 | 4,449
    ---------+---------------------------------+----------
    Total | 3,314 6,503 1,099 | 10,916

    Where NEET is binary for whether the person is "Not in Education, Employment or Training".

    How can I create a graph that represent the NEET urban population (1,179) divided by the urban population (3,314)? i.e. from the table above I need the graph bar for urban to show: 1,179/3,314=35.5%?

    When I try and represent this tabulation into a graph bar using the following command:
    -graph bar (percent) NEET, over(residency) blabel(bar, format(%3.1fc))

    The result is a graph where the bar representing the urban population reports 30.4% i.e. 3,314/10,916, which is the total urban population divided by the entire population.

    Similarly, when I try:
    -graph bar (percent) NEET if NEET==1, over(residency) blabel(bar, format(%3.1fc))

    The bar representing the urban population reports 26.5% i.e. 1,179/4,449, which is the total NEET urban population divided by the entire NEET population.


    Last edited by Amr Elshawarby; 22 Apr 2016, 12:38.

  • #2
    do you get a different result if using the -asyvars- option with your first command?

    Comment


    • #3
      Thank you, wbuchanan, for your reply.
      No, I don't get a different result when I use -asyvars- option

      Comment


      • #4
        When you tabulate, you can include the options -col row cell- to see the various percentages. It sounds like what you want are the column percentages. You want to know the percentage of the urban population in each category of NEET (they will add to 100%). You can graph the column percentages using the code below.

        This assumes the urban category of residency is coded 0, adjust accordingly:

        Code:
        graph bar (percent) residency if residency==0, over(NEET) blabel(bar, format(%3.1fc))
        Stata/MP 14.1 (64-bit x86-64)
        Revision 19 May 2016
        Win 8.1

        Comment


        • #5
          NEET is coded as 0 and 1 so you can collapse the data to calculate the percentage of NEETs by residency. Let's start by creating an example dataset.
          Code:
          clear
          input residency NEET
          1 0
          1 0
          1 1
          2 0
          2 0
          2 0
          2 0
          2 1
          2 1
          2 1
          3 0
          3 1
          end
          label def res 1 "Urban" 2 "Rural" 3 "Informal"
          label val residency res
          The percentage of NEETs by residency is as follows.
          Code:
          tab NEET residency, col
          
                     |            residency
                NEET |     Urban      Rural   Informal |     Total
          -----------+---------------------------------+----------
                   0 |         2          4          1 |         7 
                     |     66.67      57.14      50.00 |     58.33 
          -----------+---------------------------------+----------
                   1 |         1          3          1 |         5 
                     |     33.33      42.86      50.00 |     41.67 
          -----------+---------------------------------+----------
               Total |         3          7          2 |        12 
                     |    100.00     100.00     100.00 |    100.00
          Now we can collapse the data.
          Code:
          collapse (mean) NEET, by(residency)
          replace NEET = NEET * 100
          list
          
               +---------------------+
               | reside~y       NEET |
               |---------------------|
            1. |    Urban   33.33334 |
            2. |    Rural   42.85714 |
            3. | Informal         50 |
               +---------------------+
          The following command creates a bar graph with the percentage of NEETs by residency.
          Code:
          graph bar NEET, over(residency) blabel(bar, format(%5.1f)) ytitle("NEET (%)")
          Click image for larger version

Name:	graph1.png
Views:	1
Size:	10.1 KB
ID:	1337170


          If you only want to show the urban value use this command:
          Code:
          graph bar NEET if residency==1, blabel(bar, format(%5.1f)) ytitle("NEET (%)")
          Click image for larger version

Name:	graph2.png
Views:	1
Size:	7.1 KB
ID:	1337171

          Comment


          • #6
            Starting from Friedrich's example data, consider also

            Code:
            set scheme s1color 
            egen mean = mean(100 * NEET), by(residency)
            egen tag = tag(residency) 
            graph bar (asis) mean if tag, over(residency) blabel(total, format(%2.1f)) yla(0(10)60)

            Comment


            • #7
              Originally posted by Friedrich Huebler View Post
              NEET is coded as 0 and 1 so you can collapse the data to calculate the percentage of NEETs by residency.
              It is not necessary to collapse the data, the code in my previous post was unnecessarily complicated.
              Code:
              clear
              input residency NEET
              1 0
              1 0
              1 1
              2 0
              2 0
              2 0
              2 0
              2 1
              2 1
              2 1
              3 0
              3 1
              end
              label def res 1 "Urban" 2 "Rural" 3 "Informal"
              label val residency res
              
              replace NEET = NEET*100
              graph bar NEET, over(residency) blabel(bar, format(%5.1f)) ytitle("NEET (%)")

              Comment


              • #8
                Carole J. Wilson Thank you.

                Nick Cox and Friedrich Huebler Thank you, that was exactly what I'm looking for. I noticed that technically the only difference was that you took out "percent" from the graph command and instead replaced the NEET with NEET*100, hence the mean becomes the percent of frequency.

                Much appreciated.

                Comment

                Working...
                X