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

 From "Ben Jann" To statalist@hsphsun2.harvard.edu 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.
ben

On 2/28/07, William Gould, Stata <wgould@stata.com> wrote:
```
```Tom Palmer <tmp8@leicester.ac.uk> 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
wgould@stata.com
*
*   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/

```
```*
*   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/
```