. 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 |
+-------------+
Hope this helps
David
-----Original Message-----
From: Paul O'Brien [mailto:[email protected]]
Sent: 25 February 2005 12:36
To: [email protected]
Subject: st: Removing trailing letter from string
How do I remove the last letter from a string which ends with a letter but does nothing if the string ends in a digit? The string is either 3 or 4 characters long:
EC4A
EC4P
EC4Y
DA15
SE10
SE2
SE3
W1A
Thanks
Paul
Dr Paul O'Brien
Westside Contraceptive Services
Raymede Clinic, Exmoor St, London
W10 6DZ
020 8962 4450 - tel
020 8962 4451 - fax
07900 495 118 - mob
*
* 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/