Equivalent function of R's "%in%" for Stata
Asked Answered
T

3

4

Is there an equivalent function of "%in%" from R for Stata?

Tampere answered 23/2, 2011 at 13:18 Comment(3)
please describe what this operator does - people who can answer will probably know Stata, but may not know RFascista
It returns a boolean: true is lfs is in the rhs list, false otherwise.Wile
it's best if you add essential details to the question, rather than hope they are found in the commentsFascista
I
4

As already mentioned, it's hard to tell what you need from the question. inlist() might work, or it might not depending on the setting.

I find that Stata's macro lists functions are invaluable. Store your list in a macro (local or global) and then a suite of useful commands are available:

local list   a b c d d e 
local search c 
local search_in_list : list search in list
di    `search_in_list'

These can be calculated on the fly:

if `: list search in list' {
    actions if true
}
Inevitable answered 23/2, 2011 at 15:36 Comment(0)
S
2

Stata does not offer the same flexible tool, but inlist will cover the basic operation that you might be looking for, as in count if inlist(country,"FR","US","DE").

Spindell answered 7/9, 2011 at 23:31 Comment(0)
J
1

working with lists proper is one way, you could also just treat the rhs like a string and treat the lhs as a regex, use regexm()

Jeane answered 25/3, 2011 at 1:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.