Dear Statalisters,
I'd like to extract the maximum value of a Matrix (defined in mata) and use it in a Stata if function.
Look at what I've done so far using resindex and st_store commands
Stata returns :
So I have capture the maximum value of the matrix A and stored it into a Stata variable.
And the if qualifier returns that the network is weighted, which is the information I'd like to capture.
However, the Stata variable created is a real variable, what I don't need -and could even be cumbersome, even more because of the missing values-, I'd like to store this value (here 2) in a local variable.
Is there a way to do it quicker, and nicer, without passing through a real variable?
I guess I shouldn't use st_store to obtain a local in Stata, but I've try the st_numscalar commands, but it seems to do the other way around, from Stata scalar to mata Matrix.
Thanks,
Charlie
I'd like to extract the maximum value of a Matrix (defined in mata) and use it in a Stata if function.
Look at what I've done so far using resindex and st_store commands
Code:
quietly { . mata : A=(0,1\2,0) . mata : A mata: MaxA=max(A) mata: st_matrix("MaxA", MaxA) capture drop maxVal mata: resindex = st_addvar("float","maxVal") mata: st_store((1,rows(MaxA)),resindex,MaxA) noi su maxVal if maxVal[1]>1 { noi display "the network is weigthed" } else{ noi display "the network is not weigthed" } }
Code:
Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- maxVal | 1 2 . 2 2 the network is weigthed
And the if qualifier returns that the network is weighted, which is the information I'd like to capture.
However, the Stata variable created is a real variable, what I don't need -and could even be cumbersome, even more because of the missing values-, I'd like to store this value (here 2) in a local variable.
Is there a way to do it quicker, and nicer, without passing through a real variable?
I guess I shouldn't use st_store to obtain a local in Stata, but I've try the st_numscalar commands, but it seems to do the other way around, from Stata scalar to mata Matrix.
Thanks,
Charlie
Comment