Statalist The Stata Listserver


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

RE: st: right shift elements in a matrix


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: right shift elements in a matrix
Date   Thu, 18 May 2006 23:23:20 +0100

Fine, but your editing is selective. You chopped
the reference to -matselrc- 
from STB-56 in 2000, which  does the right
thing for names and covers matrices of arbitrary 
size. 

Conversely, Mata is the way forward. I infer
from this thread that Mata has no primitives 
for rotating matrices. APL had those some 
forty years ago.... 

Nick 
n.j.cox@durham.ac.uk 

Phil Schumm
 
> On May 18, 2006, at 12:06 PM, Nick Cox wrote:
> > mat b = e(b)
> > local R = rowsof(b)
> > local r = `R' - 1
> > mat b = b[1,`R'], b[1,1..`r']
> 
> 
> On May 18, 2006, at 12:28 PM, Alan Feiveson wrote:
> > Here is a way to do it using a permutation matrix C (see example  
> > below for N=4)
> 
> <snip>
> 
> > . matrix A=I(4)
> >
> > . matrix c=A[1..1,.]
> >
> > . matrix B=A\c
> 
> <snip>
> 
> > . matrix C=B[2..5,.]
> 
> <snip>
> 
> > . matrix bn=b*C
> 
> 
> These solutions are both fine and, as I noted initially, 
> resorting to  
> Mata may not necessarily have been the most appropriate strategy in  
> this case.  The only thing I'd add is a bit of advertising I  
> neglected before; the function I gave not only shifts the 
> columns but  
> also the column names (if any), and in fact, will work not only with  
> 1 x c rowvectors but also with arbitrary r x c matrices.
 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index