Here is an example that works in Stata 8.2
*---------------example--------------
sysuse auto, clear
reg price mpg rep78 headroom
matrix A = e(V)
matrix B = A /*just to make a matrix with the same dimensions*/
forvalues i = 1/4 {
forvalues j = 1/4{
matrix B[`i',`j'] = A[`i',`i'] + A[`j',`j'] - 2 * A[`i',`j']
}
}
*----------end example---------------
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z214
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of U.A.QU.AP
Sent: vrijdag 2 december 2005 18:26
To: [email protected]
Subject: Re: st: RE: matrix creation
Thanks to N. Cox, but in my original message I mean
I'd like to create a matrix B such that
B[i,j]=A[i,i]+A[j,j]-2*A[i,j]
I'm a user of Stata 8.2
---- Original message ----
>Date: Fri, 2 Dec 2005 14:07:09 -0000
>From: "Nick Cox" <[email protected]>
>Subject: st: RE: matrix creation
>To: <[email protected]>
>
>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/
*
* 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/
*
* 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/