Answers embedded below.
Nick
[email protected]
[email protected]
1. I want to replace the second word in a string varible with another
word. What is the right function?
NJC>>> If you're lucky, -subinstr()- might be enough.
Otherwise, use -split- followed by -egen, concat()-
I have looked up string functions. Unluckily, no findings.
BTW, I found -word()- was maybe useful for what I want to do. However,
missing values were always caused when I applied.
For example,
clear
input str6 v1
123
abc
2da
end
l
g v2=word(v1,2)
The result window showed "(3 missing values generated)" .
Could anyone tell me why?
NJC>>> Sure. None of these strings has more than one word. So, the
second word is empty (missing).
2.I have two string variables v1 and v2. I want to generate a new
variable v3 as following.
v1 v2 v3
abc123 123 abc
ab45 b45 a
cdef67 f67 cde
How to deal with it?
NJC>>>
gen v3 = substr(v1, 1, strpos(v1, v2) - 1)
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/