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)
synth_runner packageHello, I am working on a comparative case-study using the synthetic control method (traditionally im…
Expand observationsHello, I have a dataset of observations for companies based on different years (2016-2020). Is it p…
How does Stata plot the probability density function f (x) on the vertical axis and the quantile (0 to 1) on the horizontal axis?How does Stata plot the probability density function f (x) on the vertical axis and the quantile (0 …
Time to event graphHi, I am really appreciative of all the help that is provided here. Thank you very much. I am trying…
append error (r198)Dear Madam/Sir, I am a beginner for STATA. It will be highly appreciative if you can advise me how …
Subscribe to:
Post Comments (Atom)
0 Response to Seperating a string into substrings (by upper case letters)
Post a Comment