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]

st: matrix references with column names


From   David Kantor <[email protected]>
To   Statalist <[email protected]>
Subject   st: matrix references with column names
Date   Tue, 17 Sep 2013 14:14:54 -0400

Hello,

Suppose I have a matrix b, I want to refer to a single element using the row and column names:
b["age", "age"]

This seems to be okay for defining a 1x1 matrix, as in,
mat c = b["age", "age"]

But it is not okay when I want refer to it as a scalar quantity, such as
disp b["age", "age"]
or
scalar q = b["age", "age"]

; I get the error:
"matrix operators that return matrices not allowed in this context"

But in these contexts, it okay to refer to refer to elements by number:
disp b[2,2]

So, to refer to an element by row and column names, I seem to be forced to extract a copy:
mat c = b["age", "age"]
disp c[1,1]

Is there a better way to do this?
I can imagine searching in the rownames and colnames for the corresponding indices, but that's a lot of work; it ought to be easier than that.

I am using Stata 10. Has this changed in Stata 13?

I note that in my documentation, in [U]14.9, there is an example:
generate sdif - dif / sqrt(V["price", "price"])

which can be expected to fail.

Thanks if anyone can help with this.
--David

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