admin 发表于 2015-11-19 18:49:06

regexm筛选字符

【问题】
刚在QQ群里看到这么一个问题:
如何将下列的各种“罚款”数据筛选出来?

【方法】
1、可以将带有罚款的变量命名逐个找出来,慢慢写程序:
keep if var=="罚款滞纳金支出" | var=="罚没支出" |等等
但是,这样是否太麻烦,关键这么多会计明细,怎么可能都找出来呢。
2、利用regexm这个小运算,具体内容:
    regexm(s,re)
       Domain s:   strings
       Domain re:    regular expression
       Range:      strings
       Description:performs a match of a regular expression and evaluates to 1 if regular expression re is satisfied by the string s, otherwise returns 0.Regular expression syntax is based on Henry Spencer's NFA algorithm and this is nearly identical to the POSIX.2 standard.
【例子】
*只有带“罚”字就将其保留。
keepif regexm(var1, "罚") == 1
*其实,Excel里面很好筛选,不过没有Stata这个小运算方便。



页: [1]
查看完整版本: regexm筛选字符