Announcement

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

  • Plotting a dot graph over multiple categorical variables with three markers for each variable along y axis.

    Hello All,

    I am new to Stata data visualization (coming from R at behest of employer). I am trying to synthesize a dot chart with multiple markers along the y-axis denoting share of different responses for a list of 6 categorical variables. I have figured out how to create a dot plot over multiple BINARY variables signaling share of respondents who answered yes, but how can I do this when the variables are categorical? For reference please refer to the attached image. Thank you for your help!
    Click image for larger version

Name:	Screenshot 2023-10-11 093940.png
Views:	1
Size:	102.7 KB
ID:	1729823


    My code for binary variables has been as follows:

    *Creating Percentage Variables for Different Teacher Supports
    egen Experienced_Teacher_Yes = total(Experienced_Teacher==1)
    gen ExperiencedTeacher = (Experienced_Teacher_Yes/num_respondents)*100

    egen Teacher_Assistant_Yes = total(Teacher_Assistant==1)
    gen TeacherAssistant = (Teacher_Assistant_Yes/num_respondents)*100

    egen ICT_Coordinator_Yes = total(ICT_Coordinator==1)
    gen ICTCoordinator = (ICT_Coordinator_Yes/num_respondents)*100

    egen Other_School_Staff_Yes = total(Other_School_Staff==1)
    gen OtherSchoolStaff= (Other_School_Staff_Yes/num_respondents)*100

    egen Outside_Experts_Yes = total(Outside_Experts==1)
    gen OutsideExperts = (Outside_Experts_Yes/num_respondents)*100

    egen Online_Help_Yes = total(Online_Help==1)
    gen OnlineHelp = (Online_Help_Yes/num_respondents)*100

    egen None_Listed_Yes = total(None_Listed==1)
    gen NoneListed = (None_Listed_Yes/num_respondents)*100

    *Creating Dot Plot
    graph dot ExperiencedTeacher TeacherAssistant ICTCoordinator OtherSchoolStaff OutsideExperts OnlineHelp NoneListed, ascategory yla(0(5)50) nolabel title("Percent of Teachers Who Would Benefit From These Supports", size(medium))

  • #2
    Have your data in wide form, e.g.,

    Code:
    webuse grunfeld, clear
    collapse invest mvalue kstock, by(year)
    list, sep(0)
    Res.:

    Code:
    . list, sep(0)
    
         +-------------------------------------+
         | year    invest     mvalue    kstock |
         |-------------------------------------|
      1. | 1935    72.746    707.471     62.31 |
      2. | 1936   101.607   1079.574    74.201 |
      3. | 1937   122.481    1352.29   102.877 |
      4. | 1938    77.555    847.142   139.406 |
      5. | 1939    80.526   1080.254   155.538 |
      6. | 1940   113.265   1134.017   158.821 |
      7. | 1941   139.719   1087.948   176.832 |
      8. | 1942   122.665    880.846   203.823 |
      9. | 1943    117.79    995.164   213.618 |
     10. | 1944   120.925   1027.772   211.991 |
     11. | 1945   124.159   1140.105   219.241 |
     12. | 1946   161.359   1203.964   233.683 |
     13. | 1947   147.135    927.297    307.91 |
     14. | 1948   153.948     896.98   348.998 |
     15. | 1949   139.244    917.554   384.349 |
     16. | 1950   151.061    977.055   404.504 |
     17. | 1951   199.583   1208.084   426.607 |
     18. | 1952   224.033   1254.382   485.703 |
     19. | 1953   275.583   1477.781   564.878 |
     20. | 1954   273.781   1437.942   645.053 |
         +-------------------------------------+
    Then, you can use twoway dot, below assuming year is my categorical variable.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(year invest mvalue kstock)
    1935  72.746  707.471   62.31
    1936 101.607 1079.574  74.201
    1937 122.481  1352.29 102.877
    1938  77.555  847.142 139.406
    1939  80.526 1080.254 155.538
    1940 113.265 1134.017 158.821
    1941 139.719 1087.948 176.832
    1942 122.665  880.846 203.823
    1943  117.79  995.164 213.618
    1944 120.925 1027.772 211.991
    1945 124.159 1140.105 219.241
    1946 161.359 1203.964 233.683
    1947 147.135  927.297  307.91
    1948 153.948   896.98 348.998
    1949 139.244  917.554 384.349
    1950 151.061  977.055 404.504
    1951 199.583 1208.084 426.607
    1952 224.033 1254.382 485.703
    1953 275.583 1477.781 564.878
    1954 273.781 1437.942 645.053
    end
    format %ty year
    
    set scheme s1color
    tw dot invest mvalue kstock year, ms(Oh Oh Oh) horizontal ylab(1935/1954, angle(horiz)) ytitle("")
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	56.8 KB
ID:	1729826


    Comment


    • #3
      Thank you very much! I will make sure to put my data in wide format next time!

      Comment

      Working...
      X