Statalist


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

st: nested macros [was: RE: AW: apostrophes, quotation marks, left or right quotes?]


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: nested macros [was: RE: AW: apostrophes, quotation marks, left or right quotes?]
Date   Tue, 26 Feb 2008 14:58:43 -0000

Nesting I find easiest to understand by analogy with parenthesised
expressions in 
elementary algebra. Thus we are all taught (I presume!) to evaluate
expressions like 

(2 / (3 + 5)) 

from the inside outwards, so (3 + 5) is evaluated first, giving 8 and
then 2/8 = 1/4. 

Similarly, in 

`x`i'' 

the `i' must be evaluated first. The same principle applies to triple
and higher order nesting, 
which are in practice pretty rare. The rule is thus simply: work from
the inside outwards. 

A basic tutorial on macros is included within 

SJ-2-2  pr0005  . . . . . .  Speaking Stata:  How to face lists with
fortitude
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N.
J. Cox
        Q2/02   SJ 2(2):202--222                                 (no
commands)
        demonstrates the usefulness of for, foreach, forvalues, and
        local macros for interactive (non programming) tasks

The slides for a talk version of that paper can be found in various
places, e.g. at

http://www.cpc.unc.edu/services/computer/presentations/statatutorial/cox
_article.pdf

Nick 
n.j.cox@durham.ac.uk 

Martin Weiss

[...] the real hurdle is
to understand the macro expansion process induced by the left and right
quotes. To my - possibly limited - knowledge, there is no single place
where
you can learn it satisfactorily. In particular, the nesting mentioned by
Nick has given me headaches too many times. In fact, I still use a
trial-and-error process, coupled with -set trace on- (and the
concomitant
cluttered screen) to figure it out in complicated cases...


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index