Hello! I want to present some data using a bar chart. The statistics of interest is the mean of a binary variable (Mort30d), and I want to present it over a grouping variable (EDLOSGroup).
The correct statistics are obtained using the following command:
graph bar (mean) Mort30d, over(EDLOSGroup)
However, I would like each individual bar to include information about another grouping variable (TriageLevel) using different colors. I tried to search this forum, Youtube and I even spent over an hour with ChatGPT trying to solve this problem. The end result should look something like this:
On the y axis we have percent of 30-day mortality. On the x axis the groups (EDLOSGroup) and the colors represent the 6 possible values for TriageLevel.
The above graph was done in Excel by manually calculating the proportions of the different segments of each bar. All my attempts to achieve this in Stata has either resulted in separate bars for the secondary grouping variable - or incorrect results, like the one below:
graph bar (mean) Mort30d, over(TriageLevel) over(EDLOSGroup)stack asyvars
The problem is that I want the bar height to be based only on the mean Mort30d. The colors of the bars should represent the distribution of values in TriageLevel but only for that small part of the dataset that the bar is representing. I hope that the images makes it somewhat clear what I'm trying to accomplish.
The correct statistics are obtained using the following command:
graph bar (mean) Mort30d, over(EDLOSGroup)
However, I would like each individual bar to include information about another grouping variable (TriageLevel) using different colors. I tried to search this forum, Youtube and I even spent over an hour with ChatGPT trying to solve this problem. The end result should look something like this:
On the y axis we have percent of 30-day mortality. On the x axis the groups (EDLOSGroup) and the colors represent the 6 possible values for TriageLevel.
The above graph was done in Excel by manually calculating the proportions of the different segments of each bar. All my attempts to achieve this in Stata has either resulted in separate bars for the secondary grouping variable - or incorrect results, like the one below:
graph bar (mean) Mort30d, over(TriageLevel) over(EDLOSGroup)stack asyvars
The problem is that I want the bar height to be based only on the mean Mort30d. The colors of the bars should represent the distribution of values in TriageLevel but only for that small part of the dataset that the bar is representing. I hope that the images makes it somewhat clear what I'm trying to accomplish.
Comment