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

Re: st: Re: Extract information from a string variable

From   Steven Samuels <>
Subject   Re: st: Re: Extract information from a string variable
Date   Tue, 3 Mar 2009 09:11:26 -0500


Martyn, this may get you started.


**************************CODE BEGINS**************************
drop _all
input str8 id
label define alpha 1 "str" 0 "num"
gen id_l=length(id)
tab id_l

****assumes ID's have length <=8****

forvalues i=1/8{
gen v`i' =substr(id,`i',1)
gen alpha`i'= regexm(v`i',"[a-zA-Z]")
label values alpha`i' alpha
***************************CODE ENDS***************************

On Mar 3, 2009, at 7:58 AM, Sherriff, Martyn wrote:

I have data set which should have a string identifier of the form LLLNNLLL such as INR80TMA from which I can extract the first 3 letters, 2 numbers and last 3 letters as sub-identifiers. Unfortunately some of the data has been miscoded such as IR1NT.

How can I extract the letter, number, letter code from this, or is it a case of editing all the codes to the correct format. I am using Stata 10.

Many thanks,

*   For searches and help try:

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