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   Phil Schumm <>
Subject   Re: st: right shift elements in a matrix
Date   Thu, 18 May 2006 17:14:36 -0500

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)

. matrix A=I(4)

. matrix c=A[1..1,.]

. matrix B=A\c

. matrix C=B[2..5,.]

. 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:

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