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: foreach global macro not working with multiple macros
From
Nick Mosely <[email protected]>
To
[email protected]
Subject
Re: st: foreach global macro not working with multiple macros
Date
Wed, 2 Feb 2011 09:44:05 -0800
Statalist,
Thanks, guys. That does work, Eric. Unfortunately I have about 100
macros that I would like to loop over. Their names all start with the
letter p, so I was hoping to do something like the following:
foreach y of global p* {
I wonder, what is the use of -foreach- with macros if you can only use
one at a time?
I guess I'll have to find another way.
Thanks again for your help,
~Nick
On Wed, Feb 2, 2011 at 9:25 AM, Eric Booth <[email protected]> wrote:
> <>
>
> I also find it useful to combine the global macros before the loop (esp. if there's repetition in the elements), e.g.
>
> **************!
> global cash "pocket asdf bank"
> global check "bank"
> **
> global all: list global(cash) | global(check)
> di `"${all}"'
> **
> foreach y of global all {
> display "`y'"
> }
> **************!
> - Eric
>
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> [email protected]
>
> On Feb 2, 2011, at 11:19 AM, Eric Booth wrote:
>
>> <>
>>
>> So you could change it to:
>>
>> *****
>>> global cash "pocket"
>>> global check "bank"
>>> foreach y in $cash $check {
>>> display "`y'"
>>> }
>> *****
>>
>> to get it to work.
>>
>> - Eric
>>
>> __
>> Eric A. Booth
>> Public Policy Research Institute
>> Texas A&M University
>> [email protected]
>> Office: +979.845.6754
>>
>>
>> On Feb 2, 2011, at 11:15 AM, Maarten buis wrote:
>>
>>> --- On Wed, 2/2/11, Nick Mosely wrote:
>>>> I would like to create a for loop using global macros but
>>>> Stata continues to return an error message.
>>>>
>>>> This code works fine:
>>>>
>>>> global cash "pocket"
>>>> foreach y of global cash {
>>>> display "`y'"
>>>> }
>>>>
>>>> The following, code on the other hand, does not:
>>>>
>>>> global cash "pocket"
>>>> global check "bank"
>>>> foreach y of global cash check {
>>>> display "`y'"
>>>> }
>>>
>>> In -foreach- of local / of global you can specify only
>>> one name of a local or global macro. You specified two.
>>>
>>> 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/
>
*
* 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/