Hello,
I have a string variable called text, which consists of whole sentences, where the names of some cities appear. I am interested in creating a dummy variable if text contains some specific cities, lets say Paris, Madrid, Berlin, New York. Some of these names contains a space, like New York.
I could do it with repeted commands of strpos(text, "Paris") etc. But I have more than 10 cities so I am thinking a loop may be usefull.
What I have tried so far is the following:
generate dummy = 0
foreach city in `"Paris" "Madrid" "Berlin" "New York" ' {
replace dummy = 1 if strpos(text, " `city' ") >0
}
What I get is dummy=1 for anymatch within the text. The problem is quite obvious for New York, where I get dummy= 1 even if the word "new" appears by its own within the text, whereas I am only searching for the sequence "New York". It is also the case for Parisian for example.
I have a string variable called text, which consists of whole sentences, where the names of some cities appear. I am interested in creating a dummy variable if text contains some specific cities, lets say Paris, Madrid, Berlin, New York. Some of these names contains a space, like New York.
I could do it with repeted commands of strpos(text, "Paris") etc. But I have more than 10 cities so I am thinking a loop may be usefull.
What I have tried so far is the following:
generate dummy = 0
foreach city in `"Paris" "Madrid" "Berlin" "New York" ' {
replace dummy = 1 if strpos(text, " `city' ") >0
}
What I get is dummy=1 for anymatch within the text. The problem is quite obvious for New York, where I get dummy= 1 even if the word "new" appears by its own within the text, whereas I am only searching for the sequence "New York". It is also the case for Parisian for example.
Comment