Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: RE: Removing trailing letter from string


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: Removing trailing letter from string
Date   Fri, 25 Feb 2005 13:21:52 -0000

Quite so. 

This raises an interesting question of 
how to check (British or indeed any other) 
postcodes. Given various possibilities it 
would not be trivial, but I believe Stata provides 
all the rudimentary handles. 

Nick [home postcode DH1 2NJ] 
n.j.cox@durham.ac.uk 

David Harrison
 
> Now the discussion has moved onto upper/lower case letters, I 
> feel I should point out that my suggestion below strips off 
> anything that is not a digit between 0 and 9 - this may or 
> may not be beneficial depending on the situation, but in the 
> case of valid postcodes it should be irrelevant!
 
David Harrison 
 
> . gen newv=cond(real(substr(v,-1,1))==., substr(v,1,length(v)-1), v)
> 
> . li
> 
>      +-------------+
>      |    v   newv |
>      |-------------|
>   1. | EC4A    EC4 |
>   2. | EC4P    EC4 |
>   3. | EC4Y    EC4 |
>   4. | DA15   DA15 |
>   5. | SE10   SE10 |
>      |-------------|
>   6. |  SE2    SE2 |
>   7. |  SE3    SE3 |
>   8. |  W1A     W1 |
>      +-------------+
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index