Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Modifying a graphics command: problem with nested suboptions


From   "David Harrison" <[email protected]>
To   <[email protected]>
Subject   st: RE: Modifying a graphics command: problem with nested suboptions
Date   Thu, 8 Jun 2006 15:00:55 +0100

A couple of suggestions...

First the simple one:

Add an extra option to your command, say -byopts()- to specify any
options that need to go within the -by()-, e.g.

syntax varlist(min=2 max=2) [if] [in] [, BY(varname) byopts(string) *]


Now the more complicated one:

Allow the user to specify the options within the by (as they would in
the graph command) and strip them out again, e.g.

syntax varlist(min=2 max=2) [if] [in] [, BY(string) *]
local oldvarlist `varlist'
local oldif `if'
local oldin `in'
local oldopts `options'
local 0 `by'
syntax [varname] [, *]

Here I have used a second call to -syntax- to parse the options from
within -by()-. Note that before making this second call to -syntax- it
was necessary to rename all the locals produced by the first call to
-syntax- in order to prevent them being overwritten. You can either
rename everything back again, or else change the rest of the program to
work with `oldvarlist' etc. Following the second call to -syntax-, the
by variable will be stored as `varlist' and the by options as `options'.

Hope this helps

David

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Eva Poen
Sent: 08 June 2006 14:40
To: [email protected]
Subject: st: Modifying a graphics command: problem with nested
suboptions

Dear all,

I am in the process of writing a small graphics command. It is supposed
to produce a bar chart like

-graph bar (mean) price, over(rep78) by(foreign)-

but with the number of observations (or percentages) represented by each
bar added to the graph. The program is based on some code suggested by
Nick Cox to one of my colleagues.

So far, my syntax statement reads:

syntax varlist(min=2 max=2) [if] [in] [, BY(varname) *]

I added the * to the options list to capture any general graphics
options the user might give. But I need to explicitly state the by()
option (instead of leaving it to *), because I need the by-Variable in
some of the calculations before creating the graph.

The problem comes with the nested suboptions for -graph, twoway-. If the
user specifies the by() option in my program, some of the general
graphics options need to go inside by() for the final graph (e.g.
legend(position()), title()) while others go outside by(), like
xlabel(), xtitle(), legend(col()).

How can I best implement this in my program? I thought about adding
another option called byoption to capture everything that needs to go
inside by(), but it seems rather inelegant. Or is there an easy way to
scan the general options list created by * for the existence of by() and
extract just the variable name, for use in my calculations?

Thanks a lot,
Eva
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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