help for slideplot

Sliding bar plot for frequencies or percents

slideplot { bar | hbar } varname [weight] [if exp] [in range] , negative(valuelist) positive(valuelist) [ by(byvarlist) percent graph_options ]

slideplot { bar | hbar } varlist [weight] [if exp] [in range] , negative(varlist) positive(varlist) [ by(byvarlist) percent graph_options ]


slideplot produces a sliding bar plot showing frequencies (or optionally percents) of categories using data from one or more variables. The plot is most helpful if these categories can be ordered naturally, at least approximately.

The bar plot may be vertical or horizontal. The syntaxes slideplot bar and slideplot hbar are specified to indicate use of graph bar and graph hbar respectively. The choice is a matter of personal taste, although in general horizontal displays make it easier to identify names or labels of categories. Each bar is stacked and each straddles zero. The frequencies or percents shown are plotted as positive or negative.

There are two syntaxes. The first is for a long data structure in which categories are recorded in a single variable, which may be numeric or string. The second is for a wide data structure in which frequencies of categories are recorded in two or more variables, which must be numeric.

fweights and aweights may be specified.


negative() and positive() are required options. With the first syntax, the argument of each is a valuelist, i.e. a numeric list or a list of string values. With the second syntax, it is a varlist of numeric variables.

In the first syntax, suppose we have data in a numeric variable opinion on a 5 point opinion scale which we wish to plot, treating frequencies of 1 and 2 as positive and frequencies of 4 and 5 as negative, and ignoring the frequency of 3. The syntax is, minimally, slideplot hbar opinion, neg(5 4) pos(2 1) or slideplot bar opinion, neg(5 4) pos(2 1). Although negative() and positive() may be specified in any order, both treat the order of values literally and as specifying the order from left to right or from above to below. Thus the order of bars plotted with this example is 5 4 2 1 with bars for 5 and 4 being plotted on the negative side of 0 and bars for 2 and 1 being plotted on the positive side of 0.

Or suppose that we have data in a string variable candidate which we wish to plot in terms of votes for "Bush" (on the right, naturally) and of votes for "Gore" (on the left). The syntax is, minimally, slideplot hbar candidate, neg("Gore") pos("Bush").

In the second syntax, suppose we have data in three numeric variables, Bush, Gore and Nader, which we wish to plot. The order might deserve discussion but one possibility is slideplot hbar Bush Gore Nader, neg(Nader Gore) pos(Bush).

by() specifies that bars are to be shown separately for the distinct combinations of byvarlist. This is not a required option but in practice perhaps the most useful handle provided by slideplot. The number of variables in byvarlist must not exceed two.

percent stipulates that each bar be plotted in terms of percents of the total. Thus slideplot hbar Bush Gore Nader, neg(Nader Gore) pos(Bush) percent will show totals for Bush, Gore and Nader as percents of the total for all candidates, while slideplot hbar Bush Gore, neg(Gore) pos(Bush) percent will report Bush and Gore as percents of their total.

graph_options refers to options of graph bar or graph hbar.


. use http://www.stata-press.com/data/r8/voter.dta (candidat is 2 for Clinton, 3 for Bush) . slideplot hbar candidat [w=frac], neg(2) pos(3) by(inc) . slideplot hbar candidat [aw=pfrac], neg(2) pos(3) by(inc)

. slideplot hbar answer [w=freq], by(lifecycle car) percent neg(1 2) pos(4 5) ylabel(-60(20)60)


Nicholas J. Cox, University of Durham n.j.cox@durham.ac.uk

Also see

On-line: help for majority (if installed); catplot (if installed)