Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Mata subscripts on the left of an assignment


From   [email protected] (William Gould, Stata)
To   [email protected]
Subject   Re: st: Mata subscripts on the left of an assignment
Date   Wed, 28 Feb 2007 15:17:45 -0600

Tom Palmer <[email protected]> ended a long posting with, 

> Is Mata behaving incorrectly in code example 2 or is this my
> misunderstanding?

Mata is misbehaving in example 2.  I have just listed the problem as a bug.
Where the bug lies, however, may not be where Tom expects.

Example 2 in Tom's posting was 

        : y = (7\1\6\5)
        : p = order(y,1)
        : y = y[p]
        : y[p] = y
        : y

y should return unchanged, but it doesn't.  Tom starts with 
(7\1\6\5) and ends up with (1\1\6\1).  The line that caused 
the problem was 

        : y[p] = y

Tom asked, "Is Mata (incorrectly?) processing subscripts on the left of an
assignment on an element by element basis"?

No.  The LHS y[p] logic is fine.  The problem is that y appeared on 
the RHS of the assignment, too, and as Mata executed the y[p] from y,
the RHS changed as Mata filled in the left.  As a demonstration,


        substitute for                  the following
        -----------------------------------------------
        y[p] = y                        x = y
                                        y[p] = x
        -----------------------------------------------

The substitution will work, yet both should be equivalent.

We will fix Mata so that y[p]=y works.


-- Bill
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index