Announcement

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

  • Creating Graphs with Multiple Categories/Variables

    Hello All,

    I am fairly new to stata and trying to create a couple of different graphs. Would appreciate your help and guidance. First graph, I would like to create a graph with the average number of semesters (sem_hsgradtoenrl) it took students to enroll and I would like this by both hs class and race/ethnicity. Essentially I want to look at semesters of race/ethnicity within each class.

    Second graph, I would like to look at the relationship between students that enrolled right away or delayed enrollment (seamless_delayed) and whether or not they graduated from college, also want to look at this within race/ethnicity and for each hs class.

    Suggestions/advice is appreciated, thank you. Below is some of my data, I have defined and labelled data accordingly to my dataset.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(race_ethnicity hs_class sem_hsgradtoenrl seamless_delayed_enrolled college_grad)
    0 2  1 0 0
    1 0  0 1 0
    1 0  2 0 0
    0 0  6 0 1
    1 0  . 0 1
    1 0  4 0 1
    3 0  . 0 1
    1 0  1 0 0
    1 0  0 1 1
    1 0  0 1 1
    1 0  2 0 0
    1 0  0 1 0
    1 0  0 1 0
    1 0  0 1 1
    1 0  0 1 1
    1 0  0 1 0
    1 0  0 1 0
    1 0  0 1 1
    1 0  0 1 0
    1 1  0 1 1
    1 0  2 0 0
    1 0  0 1 0
    1 0  0 1 1
    0 0  3 0 0
    1 0  0 1 0
    0 0  0 1 1
    0 0 13 0 0
    1 1  0 1 1
    1 1  4 0 0
    1 1  0 1 1
    1 1  0 1 0
    1 1  0 1 0
    0 1  0 1 1
    2 1  0 1 0
    1 1  0 1 1
    1 1  0 1 1
    1 1  0 1 0
    0 1  0 1 0
    0 1  0 1 0
    0 1  0 1 0
    0 1  0 1 1
    1 1  0 1 1
    1 1  0 1 1
    0 1  4 0 0
    0 1  1 0 1
    1 1  0 1 1
    0 1  0 1 0
    1 1  0 1 0
    1 1  0 1 0
    1 1  3 0 0
    0 0  2 0 1
    1 0  0 1 1
    1 1  0 1 1
    1 0  0 1 1
    1 1  0 1 1
    1 1  0 1 0
    1 1  0 1 0
    1 2  0 1 1
    0 2  0 1 1
    1 2  0 1 0
    1 2  0 1 1
    1 2  0 1 0
    1 2  0 1 1
    1 2  4 0 0
    1 2  0 1 1
    1 2  0 1 0
    1 2  0 1 1
    1 2  2 0 1
    0 2  0 1 0
    1 2  5 0 0
    0 2  0 1 1
    0 1  7 0 0
    1 1  0 1 0
    1 2  0 1 1
    1 0  7 0 1
    1 1  0 1 1
    0 1  1 0 0
    0 2  5 0 0
    1 2  0 1 0
    1 1  0 1 0
    0 0  0 1 1
    0 2  0 1 0
    1 2  3 0 0
    1 2  0 1 0
    1 2  0 1 1
    1 0  8 0 0
    1 2  0 1 0
    1 0  0 1 1
    0 2  2 0 0
    0 2  3 0 0
    1 0  0 1 1
    1 2  0 1 0
    1 2  0 1 1
    1 0  5 0 0
    0 2  1 0 0
    1 2  1 0 0
    1 2  0 1 1
    0 1  0 1 0
    1 0  0 1 0
    1 0  2 0 1
    end
    label values race_ethnicity race_ethnicity
    label def race_ethnicity 0 "Hispanic or Latino", modify
    label def race_ethnicity 1 "White (Not Hispanic)", modify
    label def race_ethnicity 2 "Black or African American", modify
    label def race_ethnicity 3 "Asian", modify
    label values hs_class hs_class
    label def hs_class 0 "Class of 2015", modify
    label def hs_class 1 "Class of 2016", modify
    label def hs_class 2 "Class of 2017", modify
    label values seamless_delayed_enrolled seamless_delayed_enrolled
    label def seamless_delayed_enrolled 0 "Delayed", modify
    label def seamless_delayed_enrolled 1 "Seamless", modify
    label values college_grad college_grad
    label def college_grad 0 "No", modify
    label def college_grad 1 "Yes", modify

  • #2
    #1 Try

    Code:
    graph hbar sem_hsgradtoenrl, over(race_ethnicity) over(hs_class)
    
    graph hbar sem_hsgradtoenrl, over(hs_class) over(race_ethnicity)
    #2 That would be a graph showing four variables. Perhaps someone else can work out what you want there.

    Comment


    • #3
      Nick Cox Thank you so much! This is super helpful. Would you be able to help out with adjusting font size and bar colors? For example, class of 2015 would be blue, 2016 green, 2017 green? The same for race/ethnicity in the second option?

      Comment


      • #4
        Your journey starts with

        Code:
        help graph hbar
        and continues with clicking in turn on

        Code:
        lookofbar_options 
        
        barlook_options
        after which you will see that you need something like

        Code:
        bar(1, color(blue)) bar(2, color(green))
        although I recommend against the same colour for bars 2 and 3 -- and noting that you need asyvars to get different colours for different bars.

        Depending on how you present this, just black-and-white works as well as anything else given that you show text that explains different bars.

        Comment

        Working...
        X