help grcomb-------------------------------------------------------------------------------

Title

grcomb-- create and combine several single graphs into one

Syntax

grcombgraph commandvar1[*#] var2[*#] var3[*#] var4[*#][...] [if] [in],varblock(#)[order(abab|aabb)name(name[,replace])drawfeedbackgraph options]

byis not allowed.Weightsare not allowed.

Description

grcomballows you to generate, in a single command, several graphs of the same type and using the same options; to optionally display them; and to combine them into a single graph window. It is a wrapper for Stata's built-in graph commands, in particular thegraph combinecommand.

grcomboptions will now be further described using the following two examples. In each example, it is supposed that you want to combine three single graphs into a combined graph:(1)

scattera1 b, jitter(8)scattera2 b, jitter(8)scattera3 b, jitter(8)This is achieved by

grcombscatter a1 b a2 b a3 b, v(2) jitter(8)(2)

scattera1 b1, jitter(8)scattera2 b2, jitter(8)scattera3 b3, jitter(8)This is achieved by

grcombscatter a1 b1 a2 b2 a3 b3, v(2) jitter(8)

Options

var*#replacesvarwith#copies of itself ingrcomb's varlist. The purpose of this option will become clear shortly.

varblock(#)specifies the number of variables for a single graph command. In both examples (1) and (2), the singlescattercommands each take two variables as arguments. Therefore, varblock is 2 in both cases. If the single graph commands werehistogram, varblock would be 1, since histograms take only one variable as argument.

order(abab|aabb)specifies the order of the variables ingrcomb's varlist. The default isorder(abab)and is exemplified by both examples (1) and (2), where the variables for the single graph commands sequentially follow each other ingrcomb's varlist (e.g. in (2),a1is plotted againstb1,a2is plotted againstb2, anda3is plotted againstb3). Specifiyingorder(aabb)requires the variables to be listed in the ordera1 a2 a3 b1 b2 b3(example (2)). The point of this option is to allow simplifying the varlist toa* b*(or maybea? b?). I.e. given thata1-a3andb1-b3are the only variables starting with letters "a" and "b", respectively, thegrcombcommand in example (2) can be shortened togrcombscatter a* b*, v(2)order(aabb) jitter(8). Example (1), in turn, could be simplified togrcombscatter a* b*3, v(2) order(aabb) jitter(8), since, by way of cashing in optionvar*#,b*3expands tob b b. (Don't confuse the wildcard asterisk ,*' with the multiply operator ,*' of optionvar*#.)

name(name[,replace])lets you enter a name for the combined graph and optionally replace any previous graph of the same name. Butgrcombautomatically names your graphs for you, so you don't usually need this option.

drawdisplays the single graphs. If you omit this option, display of the single graphs (e.g. the three scatter plots in examples (1) and (2)) is suppressed.

feedbackshows feedback ongrcomb's progress in terms of the number of single graph commands it has processed.

graph optionsinclude all the options possible with the single graph command. In examples (1) and (2), this would be thejitter(8)option. You can specify here any number of options that are allowed with the single graph command you've chosen.

Remarks

grcombmay run into trouble if you have a variable in your data set with the same name as (one of the words of) your single graph command. It will recognize this for the first word of your single graph command, but not for any potential subsequent words.Example: If you have a variable

scatterin your data set and you typegrcombscatter var1 var2 var3 var4, v(2),grcombwill catch the error and ask you to remove or rename variablescatter. However, if you typegrcombtwoway scatter var1 var2 var3 var4, v(2),grcombwill crash without any helpful error message.

grcombgives unique names to both the single and the combined graphs it produces, so that none of the graphs produced by any single or consecutive calls togrcombwill be overwritten. (If you must know, the names correspond to the number of seconds expired since midnight, prefixed with the letter "g".)By default,

grcombuses thealtshrinkoption of Stata'sgraph combinecommand. At present, there's nothing you can do to change this (except editing out the word "altshrink" from "grcomb.ado".)

ExamplesPlotting temperature vs pressure for five timepoints

Awkward version:. grcombscatter temperature1 pressure1 temperature2 pressure2temperature3 pressure3 temperature4 pressure4 temperature5pressure5, v(2)

Elegant version:. grcombscatter temperature* pressure*, v(2) order(aabb)Displaying single graphs, and feedback

. grcombspineplot education sex incomeclass sex, v(2) draw fGraph commands with different numbers of arguments

Combine 3 histograms:. grcombhist age height bmi, v(1) bins(10) percent

Combine 2 scatterplots:. grcombscatter sales returns year nemploy nlayoff year, v(3)Multi-word graph commands

. grcombgraph twoway bar income nchildren education*2, v(2) order(aabb)

AuthorAlex Gamma, University Hospital of Psychiatry, Zurich, Switzerland. Email: alex.gamma@uzh.ch

Also seeManual:

[G] graph combineOnline:

[G] graph_combine,spineplot(if installed)