help mata mm_posof()
-------------------------------------------------------------------------------

Title

mm_posof() -- Find element in vector

Syntax

real scalar mm_posof(haystack, needle)

where

haystack: transmorphic vector haystack needle: transmorphic scalar needle

Description

mm_posof() returns the position of the first occurrence of element needle in vector haystack, or 0 if needle does not occur.

Note that mm_posof() is now outdated by the more flexible and faster mm_which() function. (mm_posof() has been written before the appearance of the select() function Mata.)

Remarks

mm_posof() may be used with numeric elements or with string elements. For example:

: mm_posof(("one","two","three"),("two")) 2 : mm_posof((1,2,3),(3)) 3

However:

: mm_posof((1,2,3),("2")) 0

Furthermore:

: mm_posof(("one","two","three"),("four")) 0

Conformability

mm_posof(haystack, needle) haystack: 1 x c or r x 1 needle: 1 x 1 result: 1 x 1.

Diagnostics

mm_posof() returns 0 if the element types of needle and haystack are different.

Source code

mm_posof.mata

Author

Ben Jann, ETH Zurich, jann@soz.gess.ethz.ch

Also see