Tips 84:inlist代替if条件
(2012-03-26 23:21:53)
标签:
inlist很多if条件财经 |
分类: 数据管理 |
【问题】
当很多条件时,怎么办?
【方法】
那就试试inlist吧
inlist(z,a,b,: : :)
Domain: all reals or all strings
Range: 0 or 1
Description: returns 1 if z is a member of the remaining arguments;
otherwise, returns 0.
All arguments must be reals or all must be strings. The number
of
arguments is between 2 and 255 for reals and between 2 and 10 for
strings.
【例子】
gen x= 1 if city=="beijing" | city=="Shanghai" | city=="shenzhen" |city=="hangzhou" .....
gen x= 1 if inlist(city,beijing,shanghai,shenzhen,hangzhou,....)