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

st: RE: quadratic form calculation

From   "FEIVESON, ALAN H. (AL) (JSC-SK) (NASA)" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: quadratic form calculation
Date   Mon, 7 Mar 2005 08:22:54 -0600

Stephen - This is not a complete answer to your question, but if you could
"fool" Stata into thinking your B matrix is proportional to the covariance
matrix of estimated regression coefficients where your x-variables are the
regressors, then you could use -predict- with the "stdp" option to calculate
your quadratic forms.

For example, if you regress some variable y on z1, z2, ..zM and B = (Z'Z)-1
where Z'Z is the cross-product matrix of the z's, then by adding your x's as
extra observations (outside the regresion sample), the command 

-predict blah, stdp -

would give you x'Bx times a constant (the residual mean square) for every
"new" observation.

AL Feiveson

-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Stephen P.
Sent: Monday, March 07, 2005 3:40 AM
To: [email protected]
Subject: st: quadratic form calculation

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 <[email protected]>
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:
*   For searches and help try:

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