Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: use of brace inside of macro


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: use of brace inside of macro
Date   Wed, 16 Jun 2010 07:32:39 +0000 (GMT)

--- On Wed, 16/6/10, Dr. Bill Westman wrote:
> I am curious whether a brace can be
> used inside of a macro.
> 
> For example: 
> 
> sysuse auto, clear
> macro drop _all
> 
> global test  }
> log using test, replace
> 
> forvalues j = 1/1  {
> macro list _all
> }
> 
> forvalues x = 1/1  {
> macro list _all
> ${test}
> end
> break
> ...
> causes Stata to provide r(1) error.
> 
> I've tried the macro with and without quotes "" around the
> brace.

I guess what is happening is that Stata is collecting the 
lines of code that are part of a -forvalues- block without
evaluating the local and global macros. This makes sense
to me, as often you want the values of those macros to
change across iterations of that loop. The consequence is
then that you can't use a global or local macro containing
a brace to close the loop: Stata saw the begining of the
loop, so it starts collecting lines till it sees a closing 
brace, and since it is not evaluating the macros it can't 
find the closing brace, and than runs into your -break-
command.

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
--------------------------


      

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index