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/