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   "Sergiy Radyakin" <>
To   <>
Subject   Re: st: Mata subscripts on the left of an assignment
Date   Wed, 28 Feb 2007 23:07:40 +0100

Hello Statalisters!

Not exactly to the topic, but hopefully close enough to avoid starting a new thread.
Can anybody clarify why can't I use subscripts after a call to e(something)?

. mat l e(b)

bywibs _cons
y1 -.70162747 38.106444

. mat A=e(b)[1,1]
invalid syntax

. mat B=e(b)
. mat A=B[1,1]
. mat l A
symmetric A[1,1]
r1 -.70162747

This is definitely not a bug, since intuitively e( ) is a function, but why such a behaviour with subscripts is not supported?
Is there a shorter way to extract a vector, etc from the estimates without using a temporary matrix? (in this example matrix B).


----- Original Message ----- From: "Ben Jann" <>
To: <>
Sent: Wednesday, February 28, 2007 10:29 PM
Subject: Re: st: Mata subscripts on the left of an assignment

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:

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