Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Matrix question again.


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Matrix question again.
Date   Tue, 2 Aug 2005 21:24:36 +0100

Kit Baum indicated one good solution.

Another (old-style) solution (i.e. pre-Mata) is the -matselrc- program
published in STB-56. -search matrix- would have pointed to this.

For those not on Stata 9, this program remains good for Stata 6, 7 or 8.

The help file includes this example for reversing the rows of a matrix.

     (to reverse the rows of a 4 X 5 matrix)
     . matselrc B B, r(4/1)

A more interesting question is why Amadou reports
that his code doesn't do the job. Apart from not
moving the rownames too, it looks along the right
lines.

Nick
[email protected]

[email protected]

> I have a question on how to "transpose" a matrice.
> Suppose, I have the following matrice:
>
> B[5,1]
> .1
> .3
> .5
> .7
> .9
>
> I want to reverse it into:
>
> B[5,1]
> .9
> .7
> .5
> .3
> .1
>
> I've tried the following:
>
> local n = rowsof(B)
> forval i =1/`n' {
>   local nu = `n' - `i' + 1
>   scalar ele = el(B,`nu',1)
>   mat A= nullmat(A) \ ele
> }
>
> But it is not giving me what I want.
> Any better idea?

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



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