-------------------------------------------------------------------------------
help for lgraph (Requires Version 9)                            (Version 2.0.0)
-------------------------------------------------------------------------------

Tool for drawing line graphs

lgraph yvar xvar [groupvar] [if exp] [in range] [weight] [, errortype(sd|se|#) nolegend separate(#) median quantile(# #) minmax bw fit(lfit|qfit) nomarker loptions(line_options) eoptions(error_bar_options) foptions(fitted_line_options) other_graph_options]

where yvar is the variable for which the mean will be plotted on the y-axis, and xvar is the variable that is plotted on the x-axis. It has to be a numeric variable. groupvar is the variable by which the lines will be grouped. It must be a numeric variable with group names given in their value labels.

Description

lgraph is a tool for drawing line graphs with optional error bars optionally stratified by a variable. The same can be achieved by collapsing the data using collapse and twoway. This command provides a shortcut for drawing common line graphs. Most options that are available to twoway are also available with lgraph.

Options

errortype(sd|se|#) specifies what should make up the error bars. sd gives standard deviations. se gives standard error, and # specifies the # % confidence interval of the mean. It can take any value from 50 to 100.

nolegend specifies that the legend should not be given.

separate(#) causes the points that are plotted to be slightly shifted so that the error bars do not overlap. # will usually be in the range of 0.001 to 0.05. By default, points are not shifted.

median causes the median to be plotted instead of the mean

quantile(# #) causes quantiles to be plotted as error bars. Specify the upper and lower quantiles in the bracket separated by a space, eg quantile(25 75).

minmax causes the minimum and maximum values to be plotted as error bars.

bw causes the graph to be plotted in black and white.

fit(lfit|qfit) causes a fitted line to be plotted instead of the connected line. Two types of fit are possible: linear and quadratic, corresponding to the twoway_lfit and twoway_qfit commands. The fit of the lines are weighted by the number of observations that go into each plotted mean, corresponding to using the aweight option in reg. Note that in fact all twoway subcommands can be used. Even a bar graph can be produced when combined with the separate option.

nomarker suppresses the plotting of markers in the graph, thereby rendering it a line graph instead of a connected graph.

loptions(line_options) allows extra options to be passed to twoway_connected concerning the drawing of the lines. Options should be preceeded by a number to indicate which line (unless only one line is drawn) it refers to and separated by a semicolon for different lines. e.g. loptions(3 mcolor(red) lcolor(red) ;1 mcolor(green) lcolor(green)) will cause the first line to be drawn in red and the second line to be drawn in green. Here the first line refers to the group whose groupvar = 3, and the second refers to the group whose groupvar = 1. If no number preceds the options, the option will be applied to all lines. e.g. loptions(lpat(dot) ; 1 lcolor(green)) causes all lines to be dotted and the line whose groupvar = 1 to be plotted in green.

eoptions(line_options) allows extra options to be passed to twoway_rcap concerning the drawing of the error bars. The same format applies as in loptions.

foptions(line_options) allows extra options to be passed to twoway_lfit or twoway_qfit for the fitted lines. Again the same format applies as in loptions.

other_graph_options. Include all other graph options here. e.g. ytitle("Mean number of men"), legend(on order(1 "Australia" 2 "Brazil")), etc... Titles and legends given here will override the default.

Examples: Simple line graph plotting the mean price against 1978 repair record > , stratified by origin

. sysuse auto

. lgraph price rep78 foreign, errortype(sd) separate(0.01)

To plot median and inter-quartile range instead of the mean and standard de > viation...

. lgraph price rep78 foreign, median q(25 75) separate(0.01)

To make the lines thicker and to suppress the marker...

. lgraph price rep78 foreign, errortype(sd) separate(0.01) scale(1.4) nomarker

To fit a quadratic line in black and white...

. lgraph price rep78 foreign, fit(qfit) bw

To draw even a bar graph...

. lgraph price rep78 foreign, fit(bar) fop(barw(.4)) sep(.1) nomarker legend(on order(3 "Domestic" 4 "Foreign"))

Author

Timothy Mak

Institute of Psychiatry, King's College London