I have M x M symmetric matrix B, and wish to calculate, for each obs in
my data set, the quadratic form defined by y = xBx' where x is 1 x M
vector (and x' its transpose); x is a set of variables (x1,x2,...,xM).
The dimension of M is not fixed in advance (but is typically < 10); the
number of observations in the data set is typically several thousand.
I have not discovered existing code to do this, and -findit quadratic
form- was not helpful. I want to avoid using -mkmat- (for the reasons
explained in its help file). I have looked at -matrix accum- and
-matrix vecaccum- but they don't appear to be applicable in this case --
but please correct me if I am wrong.
I was thinking of the following strategy:
1. create M (1 x M) vectors, where the Jth vector is the Jth row of B
2. create column names for these vectors using the varnames in vector x
3. use -matrix score- to create M variables, called s1,...,sM (say),
corresponding to the (Mx1) Bx' part of the quadratic form for each obs
4. generate result y = x1*s1 + x2*s2 + ... + xM*sM
Comments and suggestions please.
Stephen
-------------------------------------------------------------
Professor Stephen P. Jenkins <[email protected]>
Institute for Social and Economic Research
University of Essex, Colchester CO4 3SQ, U.K.
Tel: +44 1206 873374. Fax: +44 1206 873151.
http://www.iser.essex.ac.uk
*
* 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/