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

From |
Elmer Villanueva <evillanu@mac.com> |

To |
Statalist <statalist@hsphsun2.harvard.edu> |

Subject |
st: Stata's reporting of rows and columns in matrices |

Date |
Sat, 26 Mar 2005 11:35:01 +1100 |

Hi All!

I note that Stata has some quirky results when reporting the contents of matrices derived from operations involving transposes of other matrices. I speak of the row and column markers. Watch carefully.

I create two matrices, A and B:

. matrix A = blah blah

. matrix B = 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=A*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 calculate another matrix:

. matrix R=A'*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!

This gets really confusing when the result isn't a square matrix. Watch:

. matrix C = blah blah

. matrix list C

C[3,4]

c1 c2 c3 c4

r1 2 -3 0 1

r2 5 -1 -4 2

r3 -1 0 0 3

If I don't have a transpose, everything is fine:

. matrix S=B*C

. matrix list S

S[2,4]

c1 c2 c3 c4

r1 11 -12 0 -5

r2 -15 5 8 4

However,

. matrix T=C'*B'

. matrix list T

T[4,2]

r1 r2

c1 11 -15

c2 -12 5

c3 0 8

c4 -5 4

The row and column labels have swapped completely!

Pretty neat, eh?

Now, I realise that rows and columns can be called anything and "r" and "c" don't NEED to stand for rows and columns. In fact, I regularly use such nonsense markers as "cow" and "chicken" to stand for rows and columns in 2x2 tables to emphasise the need to concentrate on the process and not the particular elements. However, this is fascinating behaviour from Stata. Anyone care to comment?

Have a safe Easter break.

Thanks,

Elmer

Locked Bag 16 Camperdown NSW 1450

Telephone 61 2 9036 3035 Facsimile 61 2 9036 3077 Mobile 0439 947 544 www.nbcc.org.au

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

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