Announcement

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

  • Pie Chart

    graph pie rec if year == 22, over(ec_code)

    I am using above command with change of year, but stata producing same graph every time. Why so?


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int id byte year int head float(ec_code p_code) long rec
     1 22 85 1 13  282984
     1 23 85 1 13  329073
     1 24 85 1 13  369262
     2 22 86 1 13  349992
     2 23 86 1 13  502859
     2 24 86 1 13  510600
     3 22 86 1 13      -9
     3 23 86 1 13       0
     3 24 86 1 13       0
     4 22 86 1 13       0
     4 23 86 1 13       0
     4 24 86 1 13       0
     5 22 86 1 13     -10
     5 23 86 1 13       0
     5 24 86 1 13       0
     6 22 86 1 13       0
     6 23 86 1 13       0
     6 24 86 1 13       0
     7 22 86 1 13  -18613
     7 23 86 1 13       0
     7 24 86 1 13  -22258
     8 22 86 2 13    7332
     8 23 86 2 13       0
     8 24 86 2 13   11519
     9 22 86 3 13     277
     9 23 86 3 13       0
     9 24 86 3 13     400
    10 22 86 3 13   19870
    10 23 86 3 13       0
    10 24 86 3 13   20469
    11 22 86 3 13    -152
    11 23 86 3 13       0
    11 24 86 3 13       0
    12 22 86 1 13  465664
    12 23 86 1 13  600000
    12 24 86 1 13  720066
    13 22 86 1 13 -344000
    13 23 86 1 13 -400000
    13 24 86 1 13 -484214
    14 22 86 1 13   71479
    14 23 86 1 13   36775
    14 24 86 1 13   80000
    15 22 86 2 13      62
    15 23 86 2 13       0
    15 24 86 2 13       0
    16 22 86 1 13   44915
    16 23 86 1 13       0
    16 24 86 1 13   42184
    17 22 86 3 13     529
    17 23 86 3 13       0
    17 24 86 3 13       0
    18 22 20 4 13  298575
    18 23 20 4 13  330702
    18 24 20 4 13  365509
    19 22 21 4 13  293864
    19 23 21 4 13  321296
    19 24 21 4 13  355590
    20 22 23 1 13       9
    20 23 23 1 13       9
    20 24 23 1 13       8
    21 22 28 4 13       2
    21 23 28 4 13       0
    21 24 28 4 13       2
    22 22 29 5 13     736
    22 23 29 5 13    2000
    22 24 29 5 13    2100
    23 22 29 5 13      33
    23 23 29 5 13     500
    23 24 29 5 13     500
    24 22 29 5 13      75
    24 23 29 5 13       0
    24 24 29 5 13       0
    25 22 29 6 13     254
    25 23 29 6 13      52
    25 24 29 6 13      51
    26 22 29 5 13       0
    26 23 29 5 13       0
    26 24 29 5 13       0
    27 22 29 3 13       1
    27 23 29 3 13       0
    27 24 29 3 13       0
    28 22 29 6 13     266
    28 23 29 6 13      50
    28 24 29 6 13     500
    29 22 29 5 13    1491
    29 23 29 5 13       0
    29 24 29 5 13    1000
    30 22 29 5 13      26
    30 23 29 5 13      50
    30 24 29 5 13      55
    31 22 29 3 13     136
    31 23 29 3 13     900
    31 24 29 3 13     900
    32 22 29 3 13       2
    32 23 29 3 13       0
    32 24 29 3 13       0
    33 22 29 6 13       1
    33 23 29 6 13       0
    33 24 29 6 13       0
    34 22 29 5 13      52
    end
    label values year year_id
    label def year_id 22 "AE 2021-22", modify
    label def year_id 23 "RE 2022-23", modify
    label def year_id 24 "BE 2023-24", modify
    label values head rec_id
    label def rec_id 20 "Corporation Tax", modify
    label def rec_id 21 "Taxes on Income other than corporation Tax", modify
    label def rec_id 23 "Hotel Receipt Tax", modify
    label def rec_id 28 "Other Taxes on Income and Expenditure", modify
    label def rec_id 29 "Land Revenue", modify
    label def rec_id 85 "CGST", modify
    label def rec_id 86 "SGST", modify
    label values ec_code tax_id
    label def tax_id 1 "Txt", modify
    label def tax_id 2 "Into", modify
    label def tax_id 3 "Mr", modify
    label def tax_id 4 "Txo", modify
    label def tax_id 5 "Txn", modify
    label def tax_id 6 "Pr", modify
    label values p_code p_code_id
    label def p_code_id 13 "nc", modify

  • #2
    They are similar, but not identical. To see that, try

    Code:
    graph pie rec, over(ec_code) by(year)
    The negative values here in rec are troubling, but they disappear on aggregation. Provided that's generally true, pie charts are not ruled out absolutely. They are just not very good at showing the structure of your data. Indeed, your perception that the results are the same is on all fours with the point that very small values or differences are hard to discern on a pie chart, let alone between pie charts.

    Edward Tufte said this in 1983:

    A table is nearly always better than a dumb pie chart; the only worse design than a pie chart is several of them, for then the viewer is asked to compare quantities located in spatial disarray both within and between pies .... Given their low data-density and failure to order numbers along a visual dimension, pie charts should never be used.

    The Visual Display of Quantitative Information. Cheshire, CT: Graphics Press. p.178.

    Almost always bar charts out-perform pie charts. Here I used tabplot from the Stata Journal. For other examples, see e.g. https://www.statalist.org/forums/for...updated-on-ssc

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int id byte year int head float(ec_code p_code) long rec
     1 22 85 1 13  282984
     1 23 85 1 13  329073
     1 24 85 1 13  369262
     2 22 86 1 13  349992
     2 23 86 1 13  502859
     2 24 86 1 13  510600
     3 22 86 1 13      -9
     3 23 86 1 13       0
     3 24 86 1 13       0
     4 22 86 1 13       0
     4 23 86 1 13       0
     4 24 86 1 13       0
     5 22 86 1 13     -10
     5 23 86 1 13       0
     5 24 86 1 13       0
     6 22 86 1 13       0
     6 23 86 1 13       0
     6 24 86 1 13       0
     7 22 86 1 13  -18613
     7 23 86 1 13       0
     7 24 86 1 13  -22258
     8 22 86 2 13    7332
     8 23 86 2 13       0
     8 24 86 2 13   11519
     9 22 86 3 13     277
     9 23 86 3 13       0
     9 24 86 3 13     400
    10 22 86 3 13   19870
    10 23 86 3 13       0
    10 24 86 3 13   20469
    11 22 86 3 13    -152
    11 23 86 3 13       0
    11 24 86 3 13       0
    12 22 86 1 13  465664
    12 23 86 1 13  600000
    12 24 86 1 13  720066
    13 22 86 1 13 -344000
    13 23 86 1 13 -400000
    13 24 86 1 13 -484214
    14 22 86 1 13   71479
    14 23 86 1 13   36775
    14 24 86 1 13   80000
    15 22 86 2 13      62
    15 23 86 2 13       0
    15 24 86 2 13       0
    16 22 86 1 13   44915
    16 23 86 1 13       0
    16 24 86 1 13   42184
    17 22 86 3 13     529
    17 23 86 3 13       0
    17 24 86 3 13       0
    18 22 20 4 13  298575
    18 23 20 4 13  330702
    18 24 20 4 13  365509
    19 22 21 4 13  293864
    19 23 21 4 13  321296
    19 24 21 4 13  355590
    20 22 23 1 13       9
    20 23 23 1 13       9
    20 24 23 1 13       8
    21 22 28 4 13       2
    21 23 28 4 13       0
    21 24 28 4 13       2
    22 22 29 5 13     736
    22 23 29 5 13    2000
    22 24 29 5 13    2100
    23 22 29 5 13      33
    23 23 29 5 13     500
    23 24 29 5 13     500
    24 22 29 5 13      75
    24 23 29 5 13       0
    24 24 29 5 13       0
    25 22 29 6 13     254
    25 23 29 6 13      52
    25 24 29 6 13      51
    26 22 29 5 13       0
    26 23 29 5 13       0
    26 24 29 5 13       0
    27 22 29 3 13       1
    27 23 29 3 13       0
    27 24 29 3 13       0
    28 22 29 6 13     266
    28 23 29 6 13      50
    28 24 29 6 13     500
    29 22 29 5 13    1491
    29 23 29 5 13       0
    29 24 29 5 13    1000
    30 22 29 5 13      26
    30 23 29 5 13      50
    30 24 29 5 13      55
    31 22 29 3 13     136
    31 23 29 3 13     900
    31 24 29 3 13     900
    32 22 29 3 13       2
    32 23 29 3 13       0
    32 24 29 3 13       0
    33 22 29 6 13       1
    33 23 29 6 13       0
    33 24 29 6 13       0
    34 22 29 5 13      52
    end
    label values year year_id
    label def year_id 22 "AE 2021-22", modify
    label def year_id 23 "RE 2022-23", modify
    label def year_id 24 "BE 2023-24", modify
    label values head rec_id
    label def rec_id 20 "Corporation Tax", modify
    label def rec_id 21 "Taxes on Income other than corporation Tax", modify
    label def rec_id 23 "Hotel Receipt Tax", modify
    label def rec_id 28 "Other Taxes on Income and Expenditure", modify
    label def rec_id 29 "Land Revenue", modify
    label def rec_id 85 "CGST", modify
    label def rec_id 86 "SGST", modify
    label values ec_code tax_id
    label def tax_id 1 "Txt", modify
    label def tax_id 2 "Into", modify
    label def tax_id 3 "Mr", modify
    label def tax_id 4 "Txo", modify
    label def tax_id 5 "Txn", modify
    label def tax_id 6 "Pr", modify
    label values p_code p_code_id
    label def p_code_id 13 "nc", modify
    
    graph pie rec, over(ec_code) by(year)
    
    tabplot ec_code year [iw=rec], separate(ec_code) showval ytitle("") xtitle("")
    Click image for larger version

Name:	notapiechart.png
Views:	1
Size:	40.3 KB
ID:	1739591

    Comment


    • #3
      Naturally, there is scope for longer value labels and/or a different order on the vertical axis.

      Comment


      • #4
        Thank you

        Comment


        • #5
          I simply draw bar chart with different year with sort over eco_code. The command use
          graph bar (sum) rec if year == 22, over(ec_code, sort(ec_code) descending label(angle(forty_five))) blabel(total)

          Its saying variable ec_code not found, why so? where I am going wrong..

          Comment


          • #6
            Is it eco_code or ec_code?

            Comment


            • #7
              Its ec_code, I am trying to draw chart over ec_code, eco_code written by mistake

              Comment


              • #8
                Its ec_code, eco_code written by mistake

                Comment


                • #9
                  Hello Nick, please address my problem

                  Comment


                  • #10
                    I didn't realise that you still had a problem. #7 and #8 seemed to be agreeing with my guess in #6 that you had typed the variable name incorrectly.

                    With the data example in #1 the code in #5 gives me a different error message:

                    Code:
                    failed to setup collapse problem
                    r(198);
                    but this works fine:

                    Code:
                    graph bar (sum) rec if year == 22, over(ec_code, sort(1) descending) blabel(total)
                    I can't see a case for 45 degree labels.

                    Comment


                    • #11
                      Thank you so much. I was eagerly waiting for its resolution. Thanks. Why it was not founding ec_code when used within sort parenthesis.

                      Comment

                      Working...
                      X