I have a list of names and I want to know how many "words" there are by counting the empty space after trimming the front/back/double spaces.
I am getting numbers that make no sense to me.The table below is an example of my data. I expect the top name to just have 1 space and the other to have two.
I manually typed these in to make sure there was no extra space anywhere in the name (before or after)
I searched for info on strpos but the only whitespace related content I got was php stuff which I didn't quite understand.
I tested this on both Stata IC 12.1 and 13.1.
I am getting numbers that make no sense to me.The table below is an example of my data. I expect the top name to just have 1 space and the other to have two.
I manually typed these in to make sure there was no extra space anywhere in the name (before or after)
Code:
gen count=. forval i=0/10{ replace count=`i' if strpos(name, " ")==`i' }
name | count |
john smith | 5 |
john jacob smith | 5 |
I searched for info on strpos but the only whitespace related content I got was php stuff which I didn't quite understand.
I tested this on both Stata IC 12.1 and 13.1.
Comment