Dear all,
I have to "cut a string into pieces". The "seperator" being a upper case letter.
e.g. var name "AbrahamAndyGregor" should be divided in var name1 "Abraham" var name2 "Andy" and var name3 "Gregor".
There are about 180 "names" combined in different ways. I do have a list of names.
What I tried was to set the first letter to lower case -->
gen name1=(lower(substr(name, 1, 1))) + (substr(name, 2, .)) ---> name will be abrahamAndyGregor.
Thus I could extract the first name ...
gen name1 = regexs(0) if regexm(name, "[a-zäöüß ]+")
(Those freaky letters äöüß are just because they appear in the names - also blanks).
Then I tried to get the second name - and failed ;-)!
I tried different combinations like ...
gen name2 = regexs(1) if regexm(name, "(([a-zäöüß ]+)([A-ZÄÖÜ][a-zäöüß ]+))")
gen name2 = regexs(0) if regexm(name, "([A-ZÄÖÜ][a-zäöüß ]+)")
Asking the forum kindy for help - best regards,
Lynde
Related Posts with Seperating a string into substrings (by upper case letters)
what are the commands for a PVAR type model on stata?Hello! I am new on this forum and also in the use of the stata software. I'm using version 15.0 of S…
Ranking observations by a variable within two groups by yearI am working with some data on NCAA football players. For the purposes of this question, it looks so…
Generating new variables based on information in other observations in datasetI'm working with some NCAA football player data. I've reached a bit of a difficult (for me) data cle…
How to calculate the Average Treatment Effect on the Untreated (ATU) vs. ATE/ATETQuite often, I am more interested in knowing how a treatment might improve the outcomes of the untre…
Filling missing values with meanHello everyone, I am struggling with filling missing values with mean values, because I have to sep…
Subscribe to:
Post Comments (Atom)
0 Response to Seperating a string into substrings (by upper case letters)
Post a Comment