Announcement

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

  • Stacked Bar Graph Help

    Hi there!

    I am trying to create stacked bar graphs with Date on the x axis, number of cases on the y-axis and then the stacked category variable as jurisdiction which has 5 options. I am hoping to make one graph that looks at all the data and then 3 individual ones per facility. I have tried using

    graph bar (count) Case if Facility=="A", over(Date) by(Jurisdiction) stack

    Any advise would be great! We tried to make these in excel but could not reduce the gap in-between the columns enough to our liking so are trying Stata instead.
    Last edited by Katherine Millsaps; 16 Mar 2022, 14:07.

  • #2
    For an alternative to stacking see https://www.statalist.org/forums/for...updated-on-ssc noting the later update to tabplot in the Stata Journal



    SJ-20-3 gr0066_2 . . . . . . . . . . . . . . . . Software update for tabplot
    (help tabplot if installed) . . . . . . . . . . . . . . . . N. J. Cox
    Q3/20 SJ 20(3):757--758
    added new options frame() and frameopts() allowing framing
    of bars and so-called thermometer plots or charts

    SJ-17-3 gr0066_1 . . . . . . . . . . . . . . . . Software update for tabplot
    (help tabplot if installed) . . . . . . . . . . . . . . . . N. J. Cox
    Q3/17 SJ 17(3):779
    added options for reversing axis scales; improved handling of
    axis labels containing quotation marks

    SJ-16-2 gr0066 . . . . . . Speaking Stata: Multiple bar charts in table form
    (help tabplot if installed) . . . . . . . . . . . . . . . . N. J. Cox
    Q2/16 SJ 16(2):491--510
    provides multiple bar charts in table form representing
    contingency tables for one, two, or three categorical variables

    If I understand your data correctly, cases are observations and you want a three-way display by date, jurisdiction and facility.

    Here is an analogue, with the proviso that if cases are individual observations you don't need to specify frequency weights.

    Code:
    clear
    input str6 sex str8 year str1 policy int freq
    "male" "1" "A" 175
    "male" "1" "B" 116
    "male" "1" "C" 131
    "male" "1" "D" 17
    "male" "2" "A" 160
    "male" "2" "B" 126
    "male" "2" "C" 135
    "male" "2" "D" 21
    "male" "3" "A" 132
    "male" "3" "B" 120
    "male" "3" "C" 154
    "male" "3" "D" 29
    "male" "4" "A" 145
    "male" "4" "B" 95
    "male" "4" "C" 185
    "male" "4" "D" 44
    "male" "Graduate" "A" 118
    "male" "Graduate" "B" 176
    "male" "Graduate" "C" 345
    "male" "Graduate" "D" 141
    "female" "1" "A" 13
    "female" "1" "B" 19
    "female" "1" "C" 40
    "female" "1" "D" 5
    "female" "2" "A" 5
    "female" "2" "B" 9
    "female" "2" "C" 33
    "female" "2" "D" 3
    "female" "3" "A" 22
    "female" "3" "B" 29
    "female" "3" "C" 110
    "female" "3" "D" 6
    "female" "4" "A" 12
    "female" "4" "B" 21
    "female" "4" "C" 58
    "female" "4" "D" 10
    "female" "Graduate" "A" 19
    "female" "Graduate" "B" 27
    "female" "Graduate" "C" 128
    "female" "Graduate" "D" 13
    end
    
    set scheme s1color 
    tabplot policy year [w=freq], by(sex, subtitle(count by sex and year, place(w)) note(""))  showval separate(policy)


    Click image for larger version

Name:	tabplot3.png
Views:	1
Size:	19.6 KB
ID:	1654781


    Comment

    Working...
    X