graph stackbar
Bars stacked into one column per category, so the total and the parts are both visible. Good for composition; poor for comparing the middle segments, which have no common baseline.
What we have
- statistics:
count,max,mean,median,min,sum over()for the categories andby()for a second splittitle(),ytitle()andsaving()- one self-contained
.htmlfile: no server, no internet, nothing to install - a table view beside the chart, so the numbers can be read off
Coming later
- saving as PNG or SVG —
graph exportdoes not exist yet graph twowayandgraph matrix, which are refused- 84 more of the 105 catalogue chart types
How you write it
graph stackbar [(stat)] varname [if] [weight], over(catvar) by(seriesvar)
Bars stacked. Only (sum), the default, or (count): stacking adds the parts, and the sum of two averages means nothing.
What your data has to look like
One row per person or record, with these columns (named here as they are in vira.sample01):
| Column | Holds | What it does in the chart |
|---|---|---|
state | a category | one column for each state (over) |
sector | a category | the segments stacked in it, one colour each (by) |
mpce | a number | added up for each segment; use (count) to count rows instead |
Three rows of it would look like this:
Bihar Rural 2410.55 Bihar Urban 3288.1 Kerala Rural 4102.8
The example
. sysuse vira.sample01, clear . graph stackbar (count) mpce, over(state) by(sector)
That is the real file the command wrote — open it on its own. It is one self-contained page with no internet connection needed, so you can email it or drop it into a report.