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

st: chopping suffixes off values of a string variable

From   "Stephen P. Jenkins" <>
Subject   st: chopping suffixes off values of a string variable
Date   Thu, 11 Sep 2003 19:17:43 +0100 (GMT Daylight Time)

I have a string variable where values
have format 2 letters, followed by 6 digits,
followed by a letter. I'd like to create a new 
variable with values for each obs equal to the
old value except that the final letter of the
value is removed. That final suffix letter can 
range from "A" to "Z", in principle.

I suspect that there is an easy way of doing this,
but I can't think of it (nor did various searches
using -findit- reveal an easy way).  [I can only
think of a roundabout way based on creating a macro with
an alpha list in it, and then doing some looping using
subinstr function.]  Suggestions please.

(Illustration) how to convert values for
variable 'ni_number' to values of NEW_VAR,
as follows?

  | ni_number    NEW_VAR 
  | ZX223571C   ZX223571 
  | LR796192A   LR796192 
  | NE384662C   NE384662 
  | LL283409A   LL283409 
  | ZS663720B   ZS663720 
  | ZW878830B   ZW878830 
  | NM175824B   NM175824 
  | YM212595C   YM212595 
  | TA602684D   TA602684 

Professor Stephen P. Jenkins <>
Institute for Social and Economic Research (ISER)
University of Essex, Colchester, CO4 3SQ, UK
Tel: +44 (0)1206 873374. Fax: +44 (0)1206 873151.

*   For searches and help try:

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