[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
gjhxmu@sina.com |

To |
statalist<statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: RE: problems on the string functions |

Date |
Fri, 20 Nov 2009 00:47:47 +0800 |

Thank you very much, Baum and Nick. I understood the use of -subinstr-, -word- and -strpos- with your help. Another problem is how to deal with it if the strings excluded from another string variable is not consecutive. for example, clear input str10 (v1 v2) ab123d 12d efg34 f4 end I want to get v3 as followings v3 ab3 eg3 Thank you for any help. Best regards, Rose ----- Original Message ----- From: Nick Cox <n.j.cox@durham.ac.uk> To: <statalist@hsphsun2.harvard.edu> Subject: st: RE: problems on the string functions Date: 2009-11-19 23:59:43 Answers embedded below. Nick n.j.cox@durham.ac.uk gjhxmu@sina.com 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/ * * 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/

**Follow-Ups**:**RE: st: RE: problems on the string functions***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: What is good programming practice in Stata?** - Next by Date:
**st: re: What is good programming practice in Stata?** - Previous by thread:
**st: re: problems on the string functions** - Next by thread:
**RE: st: RE: problems on the string functions** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |