View and save multiple graphs with filenames based on a numeric identifier --------------------------------------------------------------------------
^mfilegr^ y-variable x-variable, ^id^var^(^string^)^ ^unit(^string^)^ [^view^|^noview^ graph_options]
Description -----------
This program constructs one two-way plot of y-var against x-var for each value of a grouping (id) variable. Each graph is saved to a file whose name is the respective value of the id variable.
Options -------
^id^var(string) where "string" is the name of an existing variable in the data that is the identifier for each group of values, y-var and x-var, for which a graph is desired. This id variable must be numeric. It is NOT optional.
^view^|^noview^ is a switch that controls display of graphs. If ^view^ is specified each graph is displayed to screen as it is saved to disk and a ^more^ condition is set such that the user must press a key to process the next graph. The default is ^noview^, so that graphs are not displayed but just saved to disk.
^unit^(string) specifies the string used to form the ^b1^(title) of the graphs. For example, if ^unit(^farm^)^ is specified, then the graphs will be entitled farm #240 farm #3567 etc, depending on the values of the id variable specified by ^id^var(). This is NOT optional.
graph_options are any of the graph options for a two-way graphic EXCEPT: (1) the ^saving()^ option, because the latter is built into the ^mfilegr^ command in a special way. (2) the ^b1(^"title"^)^ option because this is set within the program to label the graphs, depending on the argument of the ^unit^ option. There are no error traps to prevent you from specifying these options, just don't do it.
Of course many options will not make sense from one graph to another, for example, specifying values for ^ylab^(..) and ^xlab^(..) may not carry over sensibly. But a simple ^ylab^ ^xlab^, allowing Stata to choose reasonable values for each graph, may be sensible.
Example -------
. ^describe^
Contains data from dohoo.dta obs: 11 vars: 3 20 Jul 1999 20:27 size: 144 (100.0% of memory free) ------------------------------------------------------------------------ 1. id float %9.0g farm identifier 2. xvar float %9.0g rainfall 3. yvar float %9.0g crop yield ------------------------------------------------------------------------ Sorted by:
. ^list^
id xvar yvar 1. 12 4 9 2. 12 5 7 3. 12 1 2 4. 13 4 8 5. 13 6 5 6. 13 1 9 7. 23 1 8 8. 23 7 8 9. 23 4 9 10. 4890 7 1 11. 4890 12 3
. ^mfilegr^ yvar xvar, idvar(id) unit(farm) noview xlab ylab
**** no display ****
. ^dir^ *.gph 0.3k 7/20/99 23:44 12.gph 0.3k 7/20/99 23:44 13.gph 0.3k 7/20/99 23:44 23.gph 0.3k 7/20/99 23:44 4890.gph
Author ------
Dr Philip Ryan Department of Public Health University of Adelaide pryan@@medicine.adelaide.edu.au