Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Mata - generalised cross products of the form X'SX

From   Gordon Hughes <>
Subject   st: Mata - generalised cross products of the form X'SX
Date   Tue, 08 Feb 2011 12:12:59 +0000

I am starting a new thread, but this is really a follow-up to my post on performance monitoring. Following Bill Gould's helpful suggestion I have identified that most of the time is consumed in loops in my likelihood evaluation that calculate matrices of the form Z=X'SX where S is symmetric but not a diagonal matrix. Of course, I am doing things outside loops where I can.

This is a standard form in any GLS type calculation. They are not directly amenable to use with the Mata function --cross()-- but they could be got into that form by forming by factorising S=QQ', then forming P=Q'X, and finally using P=cross(P,P).

Two questions follow:

A. Is there any Mata function that does this more directly? Maybe Stata Corp might consider extending --cross()-- to handle such cases. The command --matrix glsaccum-- does this in Stata.

B. Roughly, under what conditions might this sequence of steps reduce execution time and/or memory use on the assumption that the dimension of S is large relative to cols(X)? In a related context I have to calculate X'B'BX where B is square but not symmetric and found that use of --cross()-- does not save much (if any) time, though it is probably more efficient on memory. Hence, the overhead of factorisation may not pay off. On the other hand, the initial factorisation would only need to be done once per function call, whereas the steps involving X have to be performed thousands of times per function call.

Gordon Hughes

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index