Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Macro parsing question.


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Macro parsing question.
Date   Thu, 14 Feb 2013 09:57:42 +0000

That's correct, and consistent with my previous answer. Whatever is
done last determines the value of -d-. Here you do one thing, and the
last is also the first. In the loop, you do several things, and the
last is the only one that has a lasting effect.

Nick

On Thu, Feb 14, 2013 at 9:44 AM, Amadou DIALLO <stata.diallo@gmail.com> wrote:
> Also, when I do it in the command line, I obtain what I want:
>
> . if "a" == "a" loc d %
>
> . else loc d Value
>
> . di "`d'"
> %
>
>
> 2013/2/14, Amadou DIALLO <stata.diallo@gmail.com>:
>> Hi,
>> I spent the night programming some stuffs but cannot understand why I
>> don't obtain the expected results. I was expecting "%" but got
>> "Value". What am I doing wrong?
>>
>>       noi se tr on
>>       loc list1 a
>>       loc list2 a b c
>>       loc d
>>       foreach j of loc list1 {
>>          foreach k of loc list2 {
>>             if "`j'" == "`k'" loc d %
>>             else loc d Value
>>          } // foreach k
>>                 }
>>       di "`d'"
>>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index