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   "Ben Jann" <>
Subject   Re: st: Mata subscripts on the left of an assignment
Date   Wed, 28 Feb 2007 22:29:28 +0100

Cool. I stumbled over that too some time ago and thought I was just
too stupid to understand it.

On 2/28/07, William Gould, Stata <> wrote:
Tom Palmer <> 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
*   For searches and help try:

*   For searches and help try:

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