Equivalent function of R's “%in%” for Stata

狂风中的少年 提交于 2019-12-04 03:57:09

问题


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


回答1:


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
}



回答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").




回答3:


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()



来源:https://stackoverflow.com/questions/5091426/equivalent-function-of-rs-in-for-stata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!