Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: inlist() equivalent for mata?


From   "William Gould, StataCorp LP" <[email protected]>
To   [email protected]
Subject   Re: st: inlist() equivalent for mata?
Date   Thu, 20 Mar 2014 10:07:06 -0500

Andrew Maurer <[email protected]> writes, 

> I am trying to find a mata equivalent of Stata's inlist() function, but
> have not found anything similar when looking through the directory of
> built-in mata functions. 

How about 

        sum(x :== (x1, x2, ..., xN))

This works with numbers, 

	sum(x := (1, 5, 7, 9, 11))

and it works with strings, 

        sum(s := ("this", "that", "whatever"))

sum(x := x1, x2, ..., Xn)) returns the number of matches found. 
If x1, x2, ..., Xn are distinct, it returns 1 if a match if found, 
and returns 0 otherwise. 

-- Bill
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index