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   "Nick Cox" <>
To   <>
Subject   st: RE: Modifying a graphics command: problem with nested suboptions
Date   Thu, 8 Jun 2006 15:14:57 +0100

In two words, use -gettoken-. 

First off, the -syntax- statement for -by()- is better as  

BY(str asis) 

The following code should help: 

if `"`by'"' != "" { 
	gettoken by opts : by, parse(",") 
	gettoken comma opts : opts, parse(",") 
	local byby `"by(`by', `opts')"' 

Your byvariable is now in local macro by
and you can pass local macro byby to -twoway graph-. 

You will probably need to add some flourishes
to this to get the behaviour you want. 

Other details can be seen by looking inside user-written
graphics programs that provide -by()- support. 


Eva Poen
> 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?

*   For searches and help try:

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