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

st: quadratic form calculation

From   "Stephen P. Jenkins" <>
To   <>
Subject   st: quadratic form calculation
Date   Mon, 7 Mar 2005 09:39:30 -0000

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.

Professor Stephen P. Jenkins <>
Institute for Social and Economic Research
University of Essex, Colchester CO4 3SQ, U.K.
Tel: +44 1206 873374.  Fax: +44 1206 873151.   

*   For searches and help try:

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