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

From |
Kit Baum <baum@bc.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: re: Stata's row and column labels for matrices |

Date |
Fri, 25 Mar 2005 21:08:37 -0500 |

Elmer said

"I note that Stata has some quirky results when reporting the contents=20

of matrices derived from operations involving transposes of other=20

matrices. I speak of the row and column markers. Watch carefully.

I create two matrices, A and B:

. matrix A =3D blah blah

. matrix B =3D blah blah

. matrix list A

A[2,3]

c1 c2 c3

r1 1 -1 2

r2 0 3 4

. matrix list B

B[2,3]

c1 c2 c3

r1 4 0 -3

r2 -1 -2 3

Everything's okay so far. Watch what happens when I ask for a product.

. matrix Q=3DA*B'

. matrix list Q

Q[2,2]

r1 r2

r1 -2 7

r2 -12 6

Note how the column markers are defined.

There seems to be no consistency, too. Watch what happens when I=20

calculate another matrix:

. matrix R=3DA'*B

. matrix list R

R[3,3]

c1 c2 c3

c1 4 0 -3

c2 -7 -6 12

c3 4 -8 6

Now, it's the row markers that have changed!"

I see nothing strange here. The first product (absent the DOS-inspired junk) has the number of rows of A and the number of columns of B'. Since the columns of B' are the rows of B, the result matrix should be labeled with the row names of A and the row names of B, which it is. Giving row and column names that include the matrix name make this clear:

. mat list A

A[2,3]

ac1 ac2 ac3

ar1 1 -1 2

ar2 0 3 4

. mat list B

B[2,3]

bc1 bc2 bc3

br1 4 0 -3

br2 -1 -2 3

. mat list C

C[2,2]

br1 br2

ar1 -2 7

ar2 -12 6

Likewise, the rows of the product B' A should be labeled with the column names of B (which are the row names of B'), and the columns with the column names of A, which they are in a perfectly consistent fashion:

. mat list D

D[3,3]

ac1 ac2 ac3

bc1 4 -7 4

bc2 0 -6 -8

bc3 -3 12 6

I fail to see anything unpredictable or arbitrary here. Stata matrices have named rows and columns, and those names propagate through the calculation in the same way that the numbers do. For instance,

symmetric eye[3,3]

eyec1 eyec2 eyec3

eyer1 1

eyer2 0 1

eyer3 0 0 1

. mat E = D * eye

. mat list E

E[3,3]

eyec1 eyec2 eyec3

bc1 4 -7 4

bc2 0 -6 -8

bc3 -3 12 6

This does not look quirky to me. If Stata did anything else with the names, it would.

Kit Baum, Boston College Economics

http://ideas.repec.org/e/pba1.html

*

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

- Prev by Date:
**Re: st: RE: truncate list** - Next by Date:
**st: -manova- question** - Previous by thread:
**st: Stata's reporting of rows and columns in matrices** - Next by thread:
**st: re: Stata's row and column labels for matrices** - Index(es):

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