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: Unexpected end of file in mata.


From   Amadou DIALLO <[email protected]>
To   [email protected]
Subject   Re: st: Unexpected end of file in mata.
Date   Thu, 23 Jan 2014 17:52:46 +0100

Thanks Nick.
Yes, the first part is obvious. The second one was the one I was
having trouble with.
Interesting. You mean that "i=1" is equivalent somehow to "if(i=1)"...

. mata
------------------------------------------------- mata (type end to exit) ---
: i = 2

:     if (i = 1) {
>        i
>     }
>     ;
  1

You mean that, in the second line, I am forcing i to return to 1
instead of 2? I'd never guessed such a behavior, especially since I am
in a "if" condition mode. How this could be useful in a program? I
need to think about it.
It's night here. Have a good night.
Bachir.

2014/1/23, Nick Cox <[email protected]>:
> The first point here
>
> - I am puzzled to see that mata accepts both (i=1) and (i==1). Because
> it is that flexible?
> - I don't understand why the command if (i = 1) { reassigns
> automatically i = 1 even if i = 2. What is happening here?
>
> can be peeled off. In fact, the question already hints at the answer.
>
> i == 1
>
> is, and is only, a test, whether i == 1, and the result is true or false.
>
> i = 1
>
> is, and is only, an assignment. Stata is happy with
>
> if (i = 1)
>
> which takes place in two steps
>
> i  = 1 (assignment)
>
> if (i)   (logical test).
>
> If you start with
>
> i = 1
>
> and follow with
>
> if(i = 2)
>
> then your assignment i = 2 necessarily overwrites the previous assignment.
>
> Nick
> [email protected]
>
>
> On 23 January 2014 15:44, Amadou DIALLO <[email protected]> wrote:
>
>> I have 2 remarks:
>> - I am puzzled to see that mata accepts both (i=1) and (i==1). Because
>> it is that flexible?
>> - I don't understand why the command if (i = 1) { reassigns
>> automatically i = 1 even if i = 2. What is happening here?
> *
> *   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