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

st: RE: substr() addition

From   "Nick Cox" <>
To   <>
Subject   st: RE: substr() addition
Date   Mon, 30 Sep 2002 13:40:19 +0100

> Is there a better way of trucating a string variable? I 
> just wanted to delete the
> last two characters of a variable and had to do use the 
> reverse() function
> gen str20 newdose = reverse(substr(reverse(dose),3,.)
> I was wondering whether it would have been better to have 
> the option in
> substr() to go backwards along the
> string perhaps instead of having a .  having a -. :) hence 
> instead of going
> to the end of the string with the .
> you could actually go to the start of the string....?

In addition to Michael Blasnik's comment, note
that that substr(<string>,-2,2) returns the 
last two characters of <string>, either a string 
variable or a specified string, although Adrian wants the

Depending on why you want to delete the 
last two characters, there may be another
solution with -subinstr()-. 

*   For searches and help try:

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