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

Re: st: re: Efficient, foolproof calculation of matrix quadratic form with

From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: re: Efficient, foolproof calculation of matrix quadratic form with
Date   Fri, 25 Sep 2009 11:30:08 -0500

My understanding (although I've never had a chance to really implement
this feature in my code) is that you would need to use Mata's panel*
suite, see -help mf_panelsetup-. That's called -panel- because it was
used to work with panel data, but StataCorp could just as well call it
Explicit_Kronecker* or Block_Structure*. -panel- is shorter though

Matrix operations are indeed performed at a very low level of LAPACK
routines and BLAS (co-)processor instructions. While nothing is
guaranteed, I think the average figures are that Stata ado is 3 times
slower than Mata which is 3 times slower than C code which is 10 or so
times slower than BLAS if the C code is written from scratch without
linear algebra enhancements. In case of Stata, of course, everything
is as performance optimized as possible, as the timings of my
simulations convinced me (I have a little section in my forthcoming SJ
9(3) article). Yet with sparse matrices, you might end up wasting more
time allocating memory and swapping megabytes of zeros through the
processor cache, so the smaller matrix chunks that could fit the cache
might get processed faster.

On Fri, Sep 25, 2009 at 11:12 AM, Venable <[email protected]> wrote:
> Thanks Kit. I agree that creating an NTxNT matrix would be wasteful. I
> was just hoping there was a way to avoid doing that while maintaining
> something close to the simplicity of the one-line, no-loops Kronecker
> way. (In fact, I believe your ISP book points out that matrix ops are
> often preferable to long loops. I guess this is an exception!) It seem
> that summation is indeed the simplest way, so I will proceed with that
> and try to get it right.
> Again, many thanks.
> On Fri, Sep 25, 2009 at 11:16 AM, Kit Baum <[email protected]> wrote:
>> <>
>> Venable said
>> Alternatively, I know that I could do the sum of the N terms
>> Xn'*Om_Inv_Block*Xn but I am worried that I would somehow mess this
>> up. So, another solution, I suppose, would be some idiot-proof way to
>> do this sum.
>> This is very similar to the problem of calculating the -sureg- estimator
>> (with the difference that in -sureg- there is no constraint that the X
>> matrices have the same number of columns). The -suregub- routine codes
>> -sureg- in Mata and avoids creating the monster matrix by doing the above
>> sum. It really isn't that hard to set up that loop, and if you think about
>> it, it is incredibly wasteful to be calculating the full matrix (even if
>> memory is not an issue) given the block-diagonal structure implied by the
>> Kronecker. You may find the -suregub- code in the downloadable materials
>> related to ITSP below. That routine implements -sureg- for the special case
>> where T is not necessarily equal, but it also works fine if all equations' T
>> values are the same.
>> Kit
>> Kit Baum   |   Boston College Economics & DIW Berlin   |
>>                              An Introduction to Stata Programming  |
>>   An Introduction to Modern Econometrics Using Stata  |
>> *
>> *   For searches and help try:
>> *
>> *
>> *
> *
> *   For searches and help try:
> *
> *
> *

Stas Kolenikov, also found at
Small print: I use this email account for mailing lists only.

*   For searches and help try:

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