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

st: RE: Variable/vector outer product?


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: Variable/vector outer product?
Date   Tue, 11 Jan 2005 19:23:17 -0600

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Salvati, Jean
> Sent: Tuesday, January 11, 2005 2:47 PM
> To: [email protected]
> Subject: st: Variable/vector outer product?
> 
> Hello,
> 
> I have a series u with N observations, and I want to compute the NxN
> matrix uu'. Do I have to use mkmat to do this, or is there another way?
> 
> Thanks a lot.
> 
> Jean Salvati
> 

-mkmat- would seem to be the easiest, way but you could use two -fovalue-
loops.

For example:

clear
set obs 5
gen u = _n

mkmat u,matrix(U)
matrix uu = U*U'
svmat uu
l uu*

qui {
forv i = 1/5 {
	gen c`i' = .
	forv j = 1/5 {
		replace c`i' = u[`i']*u[`j'] in `j'
		}
	}
}

l c*


Hope this helps,
Scott



*
*   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/



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