【发布时间】:2021-03-07 17:35:20
【问题描述】:
我有一些带字符串的数据,我想在找到单词时进行标记。单词将被定义为在字符串的开头、结尾或分隔一个空格。 strpos 会在字符串出现时找到,但我正在寻找类似于 subinword 的东西。 Stata 有没有办法使用subinword 的功能而不必替换它,而是标记这个词?
clear
input id str50 strings
1 "the thin th man"
2 "this old then"
3 "th to moon"
4 "moon blank th"
end
gen th_pos = 0
replace th = 1 if strpos(strings, "th") >0
上面的代码将标记每个观察,因为它们都包含“th”,但我想要的输出是:
ID strings th_sub
1 "the thin th man" 1
2 "this old then" 0
3 "th to moon" 1
4 "moon blank th" 1
【问题讨论】: