Hello everyone,
I'm new in Mata programing, but I was convinced to start with.
I'd like to call the columns of a matrix (i.e. in a foreach loop), and for each one check whether an element is positive or null.
If I were in Stata, with a matrix whose columns would be name col_1 to col_n I would have done :
However this only works with variables named col_*
In order to gain in generality (for programming purposes), I'd like it to work for any matrix.
Nb : the goal is to create some routine to compute indexes of network analysis (such as average nearest neighbor degree, etc...) that are not included yet in existing user written program. Such statistics are not very difficult to compute (I've succeeded in Stata as said above), but I lack Mata intuition for the start.
Best,
Charlie
I'm new in Mata programing, but I was convinced to start with.
I'd like to call the columns of a matrix (i.e. in a foreach loop), and for each one check whether an element is positive or null.
If I were in Stata, with a matrix whose columns would be name col_1 to col_n I would have done :
Code:
forvalues i=1/n { gen neighbor_`i'=1 if col_`i'>0 ... }
In order to gain in generality (for programming purposes), I'd like it to work for any matrix.
Nb : the goal is to create some routine to compute indexes of network analysis (such as average nearest neighbor degree, etc...) that are not included yet in existing user written program. Such statistics are not very difficult to compute (I've succeeded in Stata as said above), but I lack Mata intuition for the start.
Best,
Charlie
Comment