Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Lining up and loopy logic

From   Allan Reese <>
To   Stata distribution list <>
Subject   st: Lining up and loopy logic
Date   Thu, 11 Dec 2003 11:33:39 +0000 (GMT)

On Wed, 10 Dec 2003, Nick Cox wrote:
> Once you start changing the design by introducing
> options to fix things in absolute coordinates
> as well, it's my guess that's way beyond "not
> difficult"; it's out of the question in terms
> of the resulting complexities for programmers,
> and ultimately for users.

Anything that is logical can be programmed.  Whenever anyone tells you
that something "cannot be done because the computer doesn't allow it",
it is a fudge and a cop-out.  All I asked for is the ability to fix the
width of the inner graph region instead of it being calculated internally.

Since the question of when to use loops came up recently, here is an
example of a technique that may be widely useful for building overlaid
graphs.  The code that precedes has generated an indefinite number of
variates defining lines for groups of points: _l1, _l2 etc.  Groups are
identified by a factor, and while the x values will be ascending within
each group there is no requirement for the start of value of the next
group to be smaller, so connect(L) will not work.  The following code
generates a command line by appending a line plot for each group.  Then
the macro is executed.

* Build and execute graph command ... as a very long macro text!
  loc colours="black black blue blue dkorange dkorange /*
            */ magenta magenta emerald emerald"
* Here's the point plot ...
  loc gr "scatter `y' `x', yti("`y'")"
  forvalues i = 1 / `maxgrp' {
    loc gr ///
       "`gr'||line _l* `x' if `by'==`i', clc(`colours') legend(off)"
  `gr' // execute macro command


(1) I hve been unable to find out the maximum length for a macro string,
but some very silly examples (too many groups) appear to work.  The actual
code has rather more options for each graph

(2) it's a shame that colour names do not seem able to be abbreviated and
that, once the list is exhausted, Stata reverts to its default sequence.
*As a suggestion, I wonder if the notation DC could be added to option
lists for colours, styles, symbols etc - Da Capo to allow the list to be

(3) while my loop does not crash for silly numbers of groups, it does
generate a stream of comments linked to styles:
(note:  pstyle p16 not found in scheme, default attributes used)
(note:  named style circle not found in class markerstyle, default
attributes used
(note:  pstyle p17 not found in scheme, default attributes used)
(note:  pstyle p18 not found in scheme, default attributes used)

R. Allan Reese                       Email:
Associate Manager GRI                Direct voice:   +44 1482 466845
Graduate School                      Voice messages: +44 1482 466844
Hull University, Hull HU6 7RX, UK.   Fax:            +44 1482 466436
Be careful in handling the battery of the remote control transmitter
If swallowed consult a physician immediately for emergency treatment
               [Safety instructions: Hitachi CP-X275 data projector]

*   For searches and help try:

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