*! version 1.1.8, Alexander Staudt, 29dec2020

Title

cibar -- Plot bar graphs with confidence intervals.

Syntax

cibar
varname [if] [weight], over(varlist) [options]

Main
level(#) set confidence level; default is 95.

vce(vcetype) vcetype may be analytic (the default), cluster clustvar, bootstrap, or jackknife.

over1(varname) first over-variable (for compatibility with previous versions. See note).

over2(varname) additional over-variable.

over3(varname) additional over-variable. over3() can't be used without specifying over2().

Advanced
bargap(#) specify gap within bargroups; default is 0.

gap(#) specify gap between bargroups; default is 67 (i.e. 2/3 of a bar).

baropts(...) specify the look of the bars. For more information, see barlook_options.

barcolor(...) specify the color of the bars (see colorstyle; RGB/CMYK/HSV values are not allowed).

ciopts(...) specify the look of the range plot (see twoway rcap).

graphopts(...) specify additional graph options (see twoway_options).

barlabel(...) specify if value of the means should be displayed; default is off.

blfmt(...) specify label display format; default is %9.2f.

blposition(...) specify label position (see compassdirstyle); default is n.

blorientation(...) specify whether label text should be horizontal or vertical (see orientationstyle); default is horizontal.

blsize(...) specify label text size (see textsizestyle); default is medsmall.

blcolor(...) specify label text color (see colorstyle); default is black.

blgap(...) specify distance of barlabels from bars; default is 0.0.

by is not allowed; see by.

aweights, fweights, iweights, and pweights are allowed; see weight.

Description

cibar creates a bar plot displaying the mean of a variable and its confidence intervals, grouped over different variables.

Examples

. sysuse auto

. cibar price, over(foreign)

. cibar price, over(foreign turn)

. cibar price, over(foreign turn) level(90)

. cibar price, over(foreign turn) ciopts(lcolor(red)) graphopts(title("Price over 'foreign' over 'turn'") name(graph_1, replace))

Using the old syntax

. cibar price, over1(foreign) over2(turn) ciopts(lcolor(red)) graphopts(title("Price over 'foreign' over 'turn'") name(graph_2, replace))

Using weights

. webuse total

. cibar heartatk, over(sex race)

. cibar heartatk, over(sex race) barcol(gs0 gs10) graphopts(ylabel(, nogrid) graphregion(color(white)))

. cibar heartatk [pweight=swgt], over(sex race) graphopts(name(graph_1, replace))

. cibar heartatk [pweight=swgt], over(sex race) graphopts(name(graph_2, replace)) barlabel(on) blf(%9.3f)

Using the old syntax

. cibar heartatk [pweight=swgt], over1(sex) over2(race) graphopts(name(graph_2, replace)) barlabel(on) blf(%9.3f)

Note

over(varlist) is the preferred way to specify over-variables as of version 1.1.6. For now, over1(varname), over2(varname), over3(varname) remain valid alternatives.
over(varlist) takes precedence over over1(varname) when mixing old and new syntax.

Remarks

cibar uses -graph twoway- to draw bar graphs with confidence intervals.

cibar is designed to draw vertical bars and confidence intervals. Theoretically, horizontal bars can be specified using baropts(),
but this specification will lead to less useful graphs, as confidence intervals will still be displayed vertically. Furthermore, there will be issues concerning the x and y-axis.

The option barcolor sets the colors for the categories of the first over-variable (see examples).

The option blgap sets the distance of the barlabels from its default position. The horizontal position of the barlabels is determined by the corresponding group means and the options passed to blposition and blorientation.
To draw the bar height (group means), cibar uses Stata's added_text_options. Hence, additional space of the barlabels from the bar needs to be defined on the same scale as the y-axis (real values).

For the computation of confidence intervals using weights, cibar uses mean.

The code for this .ado is inspired by a how-to of the Institute for Digital Research and Education (IDRE), that can be found at https://stats.idre.ucla.edu/stata/faq/how-can-i-make-a-bar-graph-with-error-bars/.

Author

Alexander Staudt, staudtlex@live.de