| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: right shift elements in a matrix
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.
-- Phil
*
* 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/