Statalist


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

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


From   Bert Jung <[email protected]>
To   [email protected]
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
syntax?

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,
Bert


** 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')

end

* Graph with default xtitle
mygraph  weight mpg

* Graph with user-specified xtitle
mygraph  weight mpg, xtitle("user specified xtitle")
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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