Statalist The Stata Listserver

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

st: Re: flip a matrix around

From   Kit Baum <>
Subject   st: Re: flip a matrix around
Date   Thu, 3 Aug 2006 09:08:14 -0400

As it happens the ability to 'flip a matrix around' horizontally or vertically is the subject of a forthcoming Stata Tip. As Danielle is using Stata 9.x a Mata solution should work fine for her.

----------------cut here------------
capture program drop get_dfglsResults
program get_dfglsResults, rclass

version 9.2

local optlag = r(maiclag)
mata: st_matrix("r",flipud(st_matrix("r(results)")))
local T = r[`optlag', 5]
local df = r(N) - `optlag'
return scalar p = ttail(`df', `T')


matrix function flipud(matrix X)
return(rows(X)>1 ? X[rows(X)..1,.] : X)
----------------cut here---------------

Kit Baum, Boston College Economics
An Introduction to Modern Econometrics Using Stata:

On Aug 3, 2006, at 2:33 AM, Danielle wrote:

The problem is that the results of dfgls for each lag are listed in reverse order (i.e., results for lag m are listed first and results for lag 1 are listed last). So, the line "local T = r[`optlag', 5]" does not grab the right row. Can I flip the matrix r around so (or re-sort the rows) so that the first row corresponds to the results for lag 1 and the row m corresponds to results for lag m? Or is there perhaps a better way to approach this?
*   For searches and help try:

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