Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: extract middle of string


From   "White, Justin" <[email protected]>
To   <[email protected]>
Subject   st: RE: extract middle of string
Date   Tue, 24 Oct 2006 10:38:20 -0400

Try this:

gen str X2 = substr(x,2,.)
gen str x_2 = reverse(X2)
gen str x3 = substr(x_2,2,.)
gen str x_3 = reverse(x3)

drop X2 x_2 x3

X_3 would be the variable you are ultimately interested in.  Then rename
X_3 to whatever you wish.

HTH


Justin White

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ronnie
Babigumira
Sent: Tuesday, October 24, 2006 10:31 AM
To: [email protected]
Subject: st: extract middle of string

I have a string variable that looks like this

            x
  161011000AT
  161011000CN
1610110012CN


I am interested in what lies between the first and the last two
characters

I could have used

gen str10 = subst(x, 2, 8) but that would not work for the last
observation. How can I simply drop the first character, 
and last two charters in x

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


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index