📄 graph_bar.hlp
字号:
{smcl}
{* 28apr2005}{...}
{cmd:help graph bar} {right:dialogs: (summary statistics) {bf:{dialog bar:graph bar}} {dialog ebar:easy graph bar}}
{right:(observed data) {bf:{dialog bar_data:graph bar}} {dialog ebar_data:easy graph bar}}
{hline}
{* index bar charts}{...}
{* index over() tt option}{...}
{* index ascategory() tt option}{...}
{* index asyvars() tt option}{...}
{title:Title}
{p2colset 5 22 24 2}{...}
{p2col :{hi:[G] graph bar} {hline 2}}Bar charts{p_end}
{p2colreset}{...}
{title:Syntax}
{p 8 23 2}
{cmdab:gr:aph} {cmd:bar}{space 2}{it:yvars}
{ifin}
{weight}
[{cmd:,}
{it:options}]
{p 8 23 2}
{cmdab:gr:aph} {cmd:hbar}
{it:yvars}
{ifin}
{weight}
[{cmd:,}
{it:options}]
where {it:yvars} is
{col 20}{cmd:(asis)} {it:varlist}
or is
{col 20}[{cmd:(}{it:stat}{cmd:)}] {it:varname}{...}
[[{cmd:(}{it:stat}{cmd:)}] ...]
{...}
{col 20}[{cmd:(}{it:stat}{cmd:)}] {it:varlist}{...}
[[{cmd:(}{it:stat}{cmd:)}] ...]
{...}
{col 20}[{cmd:(}{it:stat}{cmd:)}] {it:name}{cmd:=}{it:varname} [...]{...}
[[{cmd:(}{it:stat}{cmd:)}] ...]
{pin}
where {it:stat} may be any of
{p_end}
{p 20 20 2}
{cmd:mean}
{cmd:median}
{cmd:p1}
{cmd:p2}
... {cmd:p99}
{cmd:sum}
{cmd:count}
{cmd:min}
{cmd:max}
{p_end}
or
{p 20 20 2}
any of the other {it:stats} defined in {helpb collapse}
{pin}
{cmd:mean} is the default. {cmd:p1} means 1st percentile, {cmd:p2}
second, and so on; {cmd:p50} means the same as {cmd:median}. {cmd:count}
means the number of nonmissing values of the specified variable.
{it:options}{col 40}description
{hline 70}
{help graph_bar##group_options:{it:group_options}}{...}
{col 40}groups over which bars are drawn
{help graph_bar##yvar_options:{it:yvar_options}}{...}
{col 40}variables that are the bars
{help graph_bar##lookofbar_options:{it:lookofbar_options}}{...}
{col 40}how the bars look
{help graph_bar##legending_options:{it:legending_options}}{...}
{col 40}how {it:yvars} are labeled
{help graph_bar##axis_options:{it:axis_options}}{...}
{col 40}how the numerical {it:y} axis is labeled
{help graph_bar##title_and_other_options:{it:title_and_other_options}}{...}
{col 40}titles, added text, aspect ratio, etc.
{hline 70}
{it:group_options}{marker group_options}{col 40}description
{hline 70}
{cmdab:o:ver:(}{it:varname}[{cmd:,} {help graph bar##over_subopts:{it:over_subopts}}]{cmd:)}{...}
{col 40}categories; option may be repeated
{cmd:nofill}{...}
{col 40}omit empty categories
{cmdab:miss:ing}{...}
{col 40}keep missing value as category
{cmdab:allc:ategories}{...}
{col 40}include all categories in the dataset
{hline 70}
{it:yvar_options}{marker yvar_options}{col 40}description
{hline 70}
{cmdab:asc:ategory}{...}
{col 40}treat {it:yvars} as first {cmd:over()} group
{cmdab:asy:vars}{...}
{col 40}treat first {cmd:over()} group as {it:yvars}
{cmdab:per:centages}{...}
{col 40}show percentages within {it:yvars}
{cmd:stack}{...}
{col 40}stack the {it:yvar} bars
{cmdab:cw}{...}
{col 40}calculate {it:yvar} statistics omitting
{col 40} missing values of any {it:yvar}
{hline 70}
{it:lookofbar_options}{marker lookofbar_options}{col 40}description
{hline 70}
{cmd:outergap(}[{cmd:*}]{it:#}{cmd:)}{...}
{col 40}gap between edge and first bar
{col 40} and between last bar and edge
{cmd:bargap(}{it:#}{cmd:)}{...}
{col 40}gap between {it:yvar} bars; default is 0
{cmdab:inten:sity:(}[{cmd:*}]{it:#}{cmd:)}{...}
{col 40}intensity of fill
{cmdab:linten:sity:(}[{cmd:*}]{it:#}{cmd:)}{...}
{col 40}intensity of outline
{cmdab:pcyc:le:(}{it:#}{cmd:)}{...}
{col 40}bar styles before {help pstyle:pstyles} recycle
{cmd:bar(}{it:#}{cmd:,} {it:{help barlook_options}}{cmd:)}{...}
{col 40}look of {it:#}th {it:yvar} bar
{hline 70}
{it:legending_options}{marker legending_options}{col 40}description
{hline 70}
{it:{help legend_option}}{...}
{col 40}control of {it:yvar} legend
{cmdab:nolab:el}{...}
{col 40}use {it:yvar} names, not labels, in legend
{cmdab:yvar:options:(}{help graph bar##over_subopts:{it:over_subopts}}{cmd:)}{...}
{col 40}{it:over_subopts} for {it:yvars}; rarely specified
{cmd:showyvars}{...}
{col 40}label {it:yvars} on {it:x} axis; rarely specified
{help blabel_option:{bf:{ul:blab}el(...)}}{...}
{col 40}add labels to bars
{hline 70}
{it:axis_options}{marker axis_options}{col 40}description
{hline 70}
{cmdab:yalt:ernate}{...}
{col 40}put numerical {it:y} axis on right (top)
{cmdab:xalt:ernate}{...}
{col 40}put categorical {it:x} axis on top (right)
{cmd:exclude0}{...}
{col 40}do not force {it:y} axis to include 0
{cmdab:yrev:erse}{...}
{col 40}reverse {it:y} axis
{it:{help axis_scale_options}}{...}
{col 40}{it:y}-axis scaling and look
{it:{help axis_label_options}}{...}
{col 40}{it:y}-axis labeling
{help axis_title_options:{bf:{ul:yti}tle(...)}}{...}
{col 40}{it:y}-axis titling
{hline 70}
{it:title_and_other_options}{marker title_and_other_options}{col 40}description
{hline 70}
{help added_text_option:{bf:text(...)}}{...}
{col 40}add text on graph; {it:x} range [0,100]
{help added_line_options:{bf:yline(...)}}{...}
{col 40}add {it:y} lines to graph
{it:{help aspect_option}}{...}
{col 40}constrain aspect ratio of plot region
{it:{help std_options}}{...}
{col 40}titles, graph size, saving to disk
{help by_option:{bf:by(}{it:varlist}{bf:, ...)}}{...}
{col 40}repeat for subgroups
{hline 70}
{pstd}{marker over_subopts}
The {it:over_subopts}{hline 2}used in
{cmd:over(}{it:varname}{cmd:,} {it:over_subopts}{cmd:)}
and, on rare occasion, in
{cmd:yvaroptions(}{it:over_subopts}{cmd:)}{hline 2}are
{it:over_subopts}{col 40}description
{hline 70}
{cmdab:re:label:(}{it:#} {cmd:"}{it:text}{cmd:"} ...{cmd:)}{...}
{col 40}change axis labels
{cmdab:lab:el:(}{it:{help cat_axis_label_options}}{cmd:)}{...}
{col 40}rendition of labels
{cmdab:ax:is:(}{it:{help cat_axis_line_options}}{cmd:)}{...}
{col 40}rendition of axis line
{cmd:gap(}[{cmd:*}]{it:#}{cmd:)}{...}
{col 40}gap between bars within {cmd:over()} category
{cmd:sort(}{it:varname}{cmd:)}{...}
{col 40}put bars in prespecified order
{cmd:sort(}{it:#}{cmd:)}{...}
{col 40}put bars in height order
{cmd:sort((}{it:stat}{cmd:)} {it:varname}{cmd:)}{...}
{col 40}put bars in derived order
{cmdab:des:cending}{...}
{col 40}reverse default or specified bar order
{cmdab:rev:erse}{...}
{col 40}reverse scale to run from max to min
{hline 70}
{pstd}
{cmd:aweight}s, {cmd:fweight}s, and {cmd:pweight}s are
allowed; see {help weight} and see note concerning weights in
{helpb collapse}.
{title:Description}
{pstd}
{cmd:graph} {cmd:bar} draws vertical bar charts. In a vertical
bar chart, the {it:y} axis is numerical, and the {it:x} axis is categorical.
{cmd:. graph bar (mean)} {it:numeric_var}{cmd:, over(}{it:cat_var}{cmd:)}
{it:y}
{c |}{...}
{col 47}{it:numeric_var} must be numeric;
7 {c RT} {c TLC}{hline 2}{c TRC}{...}
{col 47}statistics of it are shown on
{c |} {c |} {c |}{...}
{col 47}the {it:y} axis.
5 {c RT} {c TLC}{hline 2}{c TRC} {c |} {c |}
{c |} {c |} {c |} {c |} {c |}{...}
{col 47}{it:cat_var} may be numeric or string;
{c |} {c |} {c |} {c |} {c |}{...}
{col 47}it is shown on the categorical
{c |} {c |} {c |} {c |} {c |}{...}
{col 47}{it:x} axis.
{c BLC}{hline 2}{c BT}{hline 2}{c BT}{hline 6}{c BT}{hline 2}{c BT}{hline 9} {it:x}
first second {bf:...}
group group
{pstd}
{cmd:graph} {cmd:hbar} draws horizontal bar charts. In a horizontal bar
chart, the numerical axis is still called the {it:y} axis, and the categorical
axis is still called the {it:x} axis, but {it:y} is presented horizontally, and
{it:x} vertically.
{cmd:. graph hbar (mean)} {it:numeric_var}{cmd:, over(}{it:cat_var}{cmd:)}
{it:x}
{c |}
{c LT}{hline 6}{c TRC}
first group {c |} {c |}
{c LT}{hline 6}{c BRC}{...}
{col 48}same conceptual layout:
{c |}{...}
{col 48}{it:numeric_var} still appears
{c LT}{hline 10}{c TRC}{...}
{col 48}on {it:y}, {it:cat_var} on {it:x}
second group {c |} {c |}
{c LT}{hline 10}{c BRC}
{bf:.} {c |}
{bf:.} {c |}
{c BLC}{hline 6}{c TT}{hline 3}{c TT}{hline 6} {it:y}
5 7
{pstd}
Note that the syntax for vertical and horizontal bar charts is the same; all
that is required is changing {cmd:bar} to {cmd:hbar} or {cmd:hbar} to
{cmd:bar}.
{title:group_options}
{phang}
{cmd:over(}{it:varname}[{cmd:,} {it:over_subopts}]{cmd:)}
specifies a categorical variable over which the {it:yvars} are to be
repeated. {it:varname} may be string or numeric. Up to two {cmd:over()}
options may be specified when multiple {it:yvars} are specified, and up to
three {cmd:over()}s may be specified when a single {it:yvar} is specified;
options may be specified; see
{help graph bar##remarks2:Examples of syntax} and
{help graph bar##remarks7:Multiple over()s} under {hi:Remarks} below.
{phang}
{cmd:nofill}
specifies that missing subcategories be omitted. For instance,
consider
{phang3}
{cmd:. graph bar (mean) y, over(division) over(region)}
{pmore}
Say that one of the divisions has no data for one of the regions, either
because there are no such observations or because y==. for such
observations. In the resulting chart, the bar will be missing:
{c TLC}{c -}{c TRC} {c TLC}{c -}{c TRC} {c TLC}{c -}{c TRC} {c TLC}{c -}{c TRC} {c TLC}{c -}{c TRC}
{c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |}
{c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |}
{c -}{c BT}{c -}{c BT}{hline 4}{c BT}{c -}{c BT}{hline 4}{c BT}{c -}{c BT}{hline 7}{c BT}{c -}{c BT}{hline 11}{c BT}{c -}{c BT}{c -}
div_1 div_2 div_3 div_1 div_2 div_3
region_1 region_2
{pmore}
If you specify {cmd:nofill}, the missing category will be removed
from the chart:
{c TLC}{c -}{c TRC} {c TLC}{c -}{c TRC} {c TLC}{c -}{c TRC} {c TLC}{c -}{c TRC} {c TLC}{c -}{c TRC}
{c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |}
{c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |} {c |}
{c -}{c BT}{c -}{c BT}{hline 4}{c BT}{c -}{c BT}{hline 4}{c BT}{c -}{c BT}{hline 7}{c BT}{c -}{c BT}{hline 4}{c BT}{c -}{c BT}{c -}
div_1 div_2 div_3 div_1 div_3
region_1 region_2
{phang}
{cmd:missing}
specifies that missing values of the {cmd:over()} variables be kept as
their own categories, one for {cmd:.}, another for {cmd:.a}, etc. The
default is to act as if such observations simply did not appear in the
dataset; the observations are ignored. An {cmd:over()} variable is
considered to be missing if it is numeric and contains a missing value or
if it is string and contains "".
{phang}
{cmd:allcategories}
specifies that all categories in the entire dataset be retained for the
{cmd:over()} variables. When {cmd:if} or {cmd:in} are specified without
{cmd:allcategories}, the graph is drawn, completely excluding any
categories for the {cmd:over()} variables that do not occur in the
specified subsample. With the {cmd:allcategories} option, categories that
do not occur in the subsample still appear in the legend, and zero height
bars are drawn where these categories would appear. Such behavior can be
convenient when comparing graphs of subsamples that do not include
completely common categories for all {cmd:over()} variables. This option
has an effect only when {cmd:if} or {cmd:in} are specified or if there are
missing values in the variables.
{cmd:allcategories} may not be combined with {cmd:by()}.
{title:yvar_options}
{phang}
{cmd:ascategory}
specifies that the {it:yvars} be treated as the first {cmd:over()} group;
see {help graph bar##remarks3:Treatment of bars} under {hi:Remarks} below.
{cmd:ascategory} is a very useful option.
{pmore}
When you specify {cmd:ascategory}, results are the same as if you
specified a single {it:yvar} and introduced a new first {cmd:over()}
variable. Anyplace you read in the documentation that something is
done over the first {cmd:over()} category, or using the first
{cmd:over()} category, it will be done over or using {it:yvars}.
{pmore}
Suppose that you specified
{phang3}
{cmd:. graph bar y1 y2 y3, ascategory} {it:whatever_other_options}
{pmore}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -