I am wondering whether it wold be possible to extract information on a number of different words within a string variable in more or less the same command. I have a string containing several city names/places and i want to identify a selection of these in my dataset.
My variable looks like this (this is the reason for why i need to extract)
actiongeo_fullname
Damascus, Dimashq, Syria
Irbid, Halab, Syria
Irbid, Halab, Syria
Irbid, Halab, Syria
Irbid, Halab, Syria
Golan Heights, Syria (general), Syria
Majdal Shams, Al Qunaytirah, Syria
Majdal Shams, Al Qunaytirah, Syria
I thought the following command would be helpful, but it only returns the largecity variable=1 for all observations;
gen largecity = strpos(actiongeo_fullname, "aleppo") | strpos(actiongeo_fullname, "halab") | strpos(actiongeo_fullname, "damascus") | strpos(actiongeo_fullname, "dimashq") | strpos(actiongeo_fullname, "homs")
Is it the case that I have to make separate variables for each word/city, or is there a way to do this without separating the different places/city names from the string?
Thanks!
My variable looks like this (this is the reason for why i need to extract)
actiongeo_fullname
Damascus, Dimashq, Syria
Irbid, Halab, Syria
Irbid, Halab, Syria
Irbid, Halab, Syria
Irbid, Halab, Syria
Golan Heights, Syria (general), Syria
Majdal Shams, Al Qunaytirah, Syria
Majdal Shams, Al Qunaytirah, Syria
I thought the following command would be helpful, but it only returns the largecity variable=1 for all observations;
gen largecity = strpos(actiongeo_fullname, "aleppo") | strpos(actiongeo_fullname, "halab") | strpos(actiongeo_fullname, "damascus") | strpos(actiongeo_fullname, "dimashq") | strpos(actiongeo_fullname, "homs")
Is it the case that I have to make separate variables for each word/city, or is there a way to do this without separating the different places/city names from the string?
Thanks!
Comment