*! version 1.0 28 Jul 2020

Title

stackedcount -- produce a stacked area graph

Syntax

stackedcount
varlist
(min=2
max=2
numeric)
[if]
[in]
[,
options]

where varlist is

y x

Optional
xlabel(rule_or_values) see axis_label_options

xtick(rule_or_values) see axis_label_options

xmtick(rule_or_values) see axis_label_options

xtitle(string) see axis_title_options

xrange(numlist) see axis_scale_options

ylabel(rule_or_values) see axis_label_options

ytick(rule_or_values) see axis_label_options

ymtick(rule_or_values) see axis_label_options

ytitle(string) see axis_title_options

yscale(numlist) see axis_scale_options

caption(string) see title_options

caption(string) see title_options

note(string) see scheme_option

legend(string) see legend_options

Description

stackedcount produces a stacked area graph for the frequencies (y-axis) of the categories in a labeled numeric categorical
variable as a function of a discrete numeric variable (x-axis).

varlist is

y x

x is a numeric variable that takes on discrete values, for example calendar year, or age in years. The values of x do not need to be integers. The program will not round x or otherwise bin observations according to values of x.

y is a categorical numeric variable for which the frequencies at each value of x are to be plotted. There must be at least two distinct values. If y takes on only one value, you should just use twoway_area.

Categories will be stacked in order of the original numeric values of y, from bottom to top in order of ascending values of y.

The values of the categorical variable that is the basis of y must be labelled. If any values are unlabelled, the program will exit with error code 182.

If the categorical variable you want to plot is a string variable, encode beforehand to create a labeled numeric categorical variable.

Please see https://camerondcampbell.blog/stacked-area-graphs-in-stata/ for examples.

Options

Main

xlabel(string) see axis_label_options

xtick(rule_or_values) see axis_label_options

xmtick(rule_or_values) see axis_label_options

xtitle(string) see axis_title_options

xrange(numlist) see axis_scale_options

ylabel(rule_or_values) see axis_label_options

ytick(rule_or_values) see axis_label_options

ymtick(rule_or_values) see axis_label_options

ytitle(string) see axis_title_options

yscale(numlist) see axis_scale_options

caption(string) see title_options

caption(string) see title_options

note(string) see scheme_option

legend(string) see legend_options

Examples

stacked_percent guanzhi_js gap if gap >= 0.5 & gap <= 20 & (甲第 == 1 | 甲第 == 2) & !qiren,
legend(size(small) cols(4)) xtitle("Years since exam") ytitle("Percent")
caption("Positions held by jinshi since years since exam 甲第 1 2 - non-Banner")
note("")

Author

Cameron Campbell, HKUST.

Email camcam@ust.hk