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 <[email protected]>
To   [email protected]
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')

end

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


Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


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