Is there a command that finds the index of a certain element that equals some value from a matrix (or a vector, or series).
Or the index of the row in which column1 = some value and column2 = some other value.
Find the index of an element that equal * in a matrix
Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12067
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Find the index of an element that equal * in a matrix
There is not. You'll have to loop through the elements.
Follow us on Twitter @IHSEViews

 EViews Developer
 Posts: 2600
 Joined: Wed Oct 15, 2008 9:17 am
Re: Find the index of an element that equal * in a matrix
I think there are some tricks you can do to make it a bit easier. We'll do an example with vector objects since it's easier, you can do similar things with matrices, using the @vec and @vech and a tiny bit of math.
Here, we create a 10 element vector A and fill it with random normals, but then set A(3)=2. To find the index element containing that value, we can use the @imin function on the squares of the deviations from the desired value. We can then look up the value to make certain that it meets the test.
vector(10) a
nrnd(a)
a(3)=2
!minid =@imin(@epow(a2,2))
!minval = a(!minid)
For matrices, you can either loop over the columns, or better yet, use the @vec operator to convert into a matrix, then find the minimum vec index and convert that index back into matrix indices.
Note that in all of these cases, the identified value is not unique if there is more than one value meeting the test criterion.
Many other things can be done as a variant of the basic idea.
Here, we create a 10 element vector A and fill it with random normals, but then set A(3)=2. To find the index element containing that value, we can use the @imin function on the squares of the deviations from the desired value. We can then look up the value to make certain that it meets the test.
vector(10) a
nrnd(a)
a(3)=2
!minid =@imin(@epow(a2,2))
!minval = a(!minid)
For matrices, you can either loop over the columns, or better yet, use the @vec operator to convert into a matrix, then find the minimum vec index and convert that index back into matrix indices.
Note that in all of these cases, the identified value is not unique if there is more than one value meeting the test criterion.
Many other things can be done as a variant of the basic idea.

 EViews Developer
 Posts: 2600
 Joined: Wed Oct 15, 2008 9:17 am
Re: Find the index of an element that equal * in a matrix
One thing to note: this will give you the index of the closest value so there will be a match, even if there is no value that is equal.
Who is online
Users browsing this forum: No registered users and 11 guests