Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: simple matrix calculations

From   Mark Schaffer <>
To, Stuart Jordan <sjordan@Princeton.EDU>
Subject   Re: st: simple matrix calculations
Date   Wed, 05 Feb 2003 00:11:29 +0000 (GMT)

You want to use matrix accumulate.  If X is n by k1, and Z is n by k2, then

mat accum XZ = X Z, nocons

(assuming that you already have or don't need a constant column)

results in the (k1+k2) by (k1+k2) cross-product matrix called XZ.  The 
upper-left-hand k1 by k1 block of XZ is X'X, the lower-right-hand k2 by k2 
block of XZ is Z'Z, and the off-diagonal blocks (k1 by k2 and k2 by k1) are 
X'Z and Z'X.

Hope this is what you are looking for....


Quoting Stuart Jordan <sjordan@Princeton.EDU>:

> I am trying to find a simple way to compute X'Z in stata where X is
> an n
> by k matrix, and Z is an n by l matrix with k>=l, and where these
> matrices are made up of columns of observations from my dataset. 
> The
> stata programming manual makes it sound as if this should be
> straightfoward using one of the matrix accum commands...but the
> only
> ways I've been able to figure out how to do it with these commands
> require a burdensome amount of complicated code.
> I'm not able to do this using the mkmat command because my dataset
> is
> too large given stata 8's maximum matsize of 800.
> In case it matters, the application I want to use this for is to
> compute
> X'Z where X is a matrix of observations on a set of exogenous
> regressors
> and instruments and Z is a matrix of observation on a set of the
> same
> exogenous regressors and a set of endogenous regressors.
> Even though I could do this in Matlab or Gauss easily, I use stata
> more
> often, so would like to learn how to do it there.
> Thanks,
> Stu Jordan
> *
> *   For searches and help try:
> *
> *
> *

Prof. Mark Schaffer
Director, CERT
Department of Economics
School of Management & Languages
Heriot-Watt University, Edinburgh EH14 4AS
tel +44-131-451-3494 / fax +44-131-451-3008


This e-mail and any files transmitted with it are confidential
and intended solely for the use of the individual or entity to
whom it is addressed.  If you are not the intended recipient
you are prohibited from using any of the information contained
in this e-mail.  In such a case, please destroy all copies in
your possession and notify the sender by reply e-mail.  Heriot
Watt University does not accept liability or responsibility
for changes made to this e-mail after it was sent, or for
viruses transmitted through this e-mail.  Opinions, comments,
conclusions and other information in this e-mail that do not
relate to the official business of Heriot Watt University are
not endorsed by it.
*   For searches and help try:

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