[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Accessing and changing -graph- options in a program

From   Bert Jung <>
Subject   st: Accessing and changing -graph- options in a program
Date   Mon, 23 Feb 2009 15:32:51 -0500

Dear Statalisters,

I am writing a program that customizes a graph.  I want the common
-graph- options to be available in my program, but override some of
them with settings that I define in the program itself.  I am looking
for a way to access and change some of the allowed -graph- options
inside my program.

In the below example, if the user does not specify the option - ,
xtitle() - the program assigns a default value.  I can implement this
by specifying my own option xtitle() in the syntax and then
substituting the content of the `xtitle' macro.  But there must be a
better way to access all those options than listing them in the

More generally I would also like to change suboptions such as - ,
xscale( range() ) - with my own values.  Is there a direct access to
the values in - range() -?  My alternative is to pass a string to -
xscale() - which would require parsing and validation.

Any suggestions warmly welcome,

** Example for xtitle

sysuse auto, clear

cap program drop mygraph
program mygraph

    syntax varlist(min=2 max=2), [ xtitle(string) ]

      * If xtitle is not user-specified, use the default xtitle
    if "`xtitle'" == "" {
        local xtitle = "default xtitle"

    di "varlist is -> `varlist'"
    di "xtitle is  -> `xtitle'"

    scatter `varlist', xtitle(`xtitle')


* Graph with default xtitle
mygraph  weight mpg

* Graph with user-specified xtitle
mygraph  weight mpg, xtitle("user specified xtitle")
*   For searches and help try:

© Copyright 1996–2022 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index