Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: replace and strpos


From   "Ona McCarthy" <omccarthy@tccr.org.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: replace and strpos
Date   Wed, 15 Aug 2012 10:12:17 +0100

Hello,

I have a list of around 300 postcodes that are string variables. I need to change the postcode strings into their corresponding borough. I succeeded in doing this to some extent by writing commands for each string value using replace and strops. E.g.:

replace borough  = "Camden" if strpos(postcode, "NW1")

A problem arises when I run all the commands and it comes to a postcode that contains some characters that are also in another postcode, i.e. it overwrites the original.

E.g. the above "Camden" is overwritten by "Westminster" when this command is run:

replace borough  = "Westminster" if strpos(postcode, "W1")

Because it shares the "W1".

Is there any way I can tell Stata to look for the EXACT postcode? I've looked all around and can't figure it out.

Thanks,

Ona


  



______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index