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: Macro parsing question.


From   Amadou DIALLO <[email protected]>
To   [email protected]
Subject   Re: st: Macro parsing question.
Date   Thu, 14 Feb 2013 19:07:57 +0100

Dear Nick,

Indeed both, I guess. What I don't understand, why the logic of this
rule is not applying when in a loop mode:

- foreach i of loc list1 {
- foreach k of loc list2 {
- if "`i'" == "`k'" local d = cond("a" == "c", "%", "Value")
= if "a" == "a" local d = cond("a" == "c", "%", "Value")
- di "`d'"
= di "Value"
Value
- }
- if "`i'" == "`k'" local d = cond("a" == "c", "%", "Value")
= if "a" == "b" local d = cond("a" == "c", "%", "Value")
- di "`d'"
= di "Value"
Value
- }
- if "`i'" == "`k'" local d = cond("a" == "c", "%", "Value")
= if "a" == "c" local d = cond("a" == "c", "%", "Value")
- di "`d'"
= di "Value"
Value
- }
- }


Here:
= if "a" == "a" local d = cond("a" == "c", "%", "Value")
- di "`d'"
= di "Value"
Value

"a" == "a" so why d evaluates to "Value"?


2013/2/14, Nick Cox <[email protected]>:
> In turn I don't understand this new question.
>
> It seems that you don't understand the code you have written or my
> explanation of why the results it gives are perfectly expectable;
> indeed both.
>
> Perhaps you should explain what you want the code to do, because it is
> evidently not doing it.
>
> Nick
>
> On Thu, Feb 14, 2013 at 4:12 PM, Amadou DIALLO <[email protected]>
> wrote:
>> Thanks Nick,
>> I have not quite understand your answer. The thing, I have to include
>> the evaluation within a loop. Why, when inserting in the loop this is
>> not working?
>> Regards.
>> Bachir.
>>
>> 2013/2/14, Nick Cox <[email protected]>:
>>> 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 <[email protected]>
>>> 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 <[email protected]>:
>>>>> 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/
>>>
>>
>>
>> --
>> Amadou B. DIALLO, PhD.
>> Senior Economist, AfDB.
>> [email protected]
>> +21671101789
>> *
>> *   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/
> *
> *   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/
>


-- 
Amadou B. DIALLO, PhD.
Senior Economist, AfDB.
[email protected]
+21671101789
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index