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

st: RE: matrix creation


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: matrix creation
Date   Fri, 2 Dec 2005 14:07:09 -0000

I am not sure if you mean what you say, as 
B appears on both sides here. However, 
assuming by Statalist convention that
you are using Stata 9.1, in Mata the 
following code, given a matrix A, may help: 

B = A 

for(i = 1; i <= rows(A) ; i++) { 
	for(j = 1; j <= cols(A); j++) { 
		B[i,j] = A[i,i] + A[j,j] - 2 * A[i,j] 
	}
}

Note how close is it to your algebra. 

Nick 
[email protected] 

U.A.QU.AP (a.k.a. AbdelRahmen) 

> I have a square matrix A (100x100). I'd to create a matrix B 
> such that
> B[i,j]=A[i,i]+B[j,j]-2*A[i,j]

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