Stata技巧 - 使用subinstr()计算子串的数量
(2015-06-15 11:58:31)
标签:
statasubinstr()strlen()子串个数 |
分类: Stata |
问题描述:计算一篇论文中作者的数量;
数据描述:核心变量为Author,如果有多个作者的,中间用逗号分隔。
解决思路:1.将问题转化为计数Comma的个数,然后加1得到作者数量。
Stata
gen AuthorNum = strlen(Author) -
strlen(subinstr(Author,",","",.)) + 1
参考
Cox, Nicholas J. "Stata tip 98: Counting substrings within
strings."
原文链接