Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: doubt on Mata using multiple loops


From   Gioia de Melo <gioiademelo@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: doubt on Mata using multiple loops
Date   Sat, 13 Mar 2010 09:44:09 -0300

Hi,

I have problems linking two matrices with for and if.
Matrix X is of n*5, in the first column it identifies firms, columns 2:5
identify firms that are connected to firm in column 1. I need to create a
symmetric matrix A nxn that has 1 in cells between two firms that are
connected.

I run this program but it does not alter A although it does not point any
error:


mata

A=J(20,20,0)

X = st_data(.,.)

for (i=2;i<=cols(X);i++) {
for (j=1;j<=rows(X);j++){
for (i1=1;i1<=cols(A);i1++) {
for (j1=1;j1<=rows(A);j1++){
if (j1==j & i1== X[j,i]){
A[j1,i1]==1
}
}
}
}
}
end

Thank you for your help.

Gioia

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index