Announcement

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

  • How do you make pie chart by combining two variables in stata?


    How do you make pie chart by combining two variables in stata?. For example, make pie charts by sex (male, female) and studies (yes, no).

  • #2
    Surely there is a better display unless your audience is small children? But I guess that something like

    Code:
    graph pie, over(sex) by(studies)
    may be what you are asking for.

    Comment


    • #3
      If I understand graph pie correctly, Nick's answer will produce two pies - for studies yes and no - each with two pieces - for sex male and female.

      If instead you wanted a single pie with four pieces - for the four combinations of sex and studies - you will want to create a single variable taking four distinct values corresponding to the four combinations (perhaps using egen with its group function) and use that as the argument to the over option, dropping the by option.

      Myself, I would likely produce a two-by-two tabulation and trust that my readers can comprehend it and draw their own conclusions about how the pieces compare.

      Comment


      • #4
        Pie charts would surely raise eyebrows from those with much expertise, and that for good reason.

        Considered as "evil" by some author , the worst type of graph by other, it has been so despised, to the point that R, when we search the term "pie", gives this note:

        Pie charts are a very bad way of displaying information. The eye is good at judging linear measures and bad at judging relative areas. A bar chart or dot chart is a preferable way of displaying this type of data.
        Also in the note, an excerpt from Cleveland, W. S. (1985) The Elements of Graphing Data. Wadsworth: Monterey, CA, USA, page 264:

        “Data that can be shown by pie charts always can be shown by a dot chart. This means that judgements of position along a common scale can be made instead of the less accurate angle judgements.”
        These aspects being raised, I decided to share command and toy graph below, albeit with the hope of not having commited some sort of heresy, but mainly for the sake of giving a helping hand to a new fellow, and, on top of that, just for amusing myself with Stata.

        Code:
        . sysuse auto
        (1978 Automobile Data)
        
        . drop if rep78 ==.
        (5 observations deleted)
        
        . label define rep78 1 "Rep = 1" 2 "Rep = 2" 3 "Rep = 3" 4 "Rep = 4" 5 "Rep = 5"
        
        . label values rep78 rep78
        
        . egen float for_rep = group(foreign rep78), label lname(mylabel)
        
        . graph pie, over(for_rep) plabel(_all percent, format("%2.1f") size(small)) title("Beware: No sure pie chart should be a good idea...") note("Told you: so little information with so much fuss!")
        Click image for larger version

Name:	Graph_pie_Marcos.png
Views:	1
Size:	18.5 KB
ID:	1376827

        Last edited by Marcos Almeida; 04 Mar 2017, 11:22.
        Best regards,

        Marcos

        Comment

        Working...
        X