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

st: RE: Replace string

From   "Steichen, Thomas J." <[email protected]>
To   <[email protected]>
Subject   st: RE: Replace string
Date   Wed, 2 Mar 2005 13:54:47 -0500


Use function subinstr(s1,s2,s3,n), which returns s1 where the first n occurrences 
in s1 of s2 have been replaced with s3.  If n is missing (.), all occurrences are replaced.

Thus if your field is called -datefield-:

  replace datefield = subinstr(datefield,"00", "2000",.) 


Thomas J. Steichen
[email protected]
  Facts do not cease to exist because they are ignored. - Aldous Huxley

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of 
> Robin Newberry
> Sent: Wednesday, March 02, 2005 1:46 PM
> To: [email protected]
> Subject: st: Replace string
> As an easy way to group accidents by year, the data has a field with 
> simply the year of the accident. Unfortunately, they've chosen to 
> enter 2 date years, rather than 4 date years. This presents 2 
> problems:
> 1) 9999 is sometimes entered as shorthand for "date unknown"
> 2) There are other weird things in there too, (like I93 for an 
> accident in 1993)
> What I'd like to do is clean this up to 4 digit years; I realize some 
> things will just have to be hand edited, but is there a way to batch 
> replace -00- with -2000-?
> -- 
> Robin
> --------------------------------------------------------------
> W. Robert Newberry, IV CIH, CHMM
> Chief Environmental Health and Safety Officer
> Clemson University
> [email protected]  [email protected]
> *
> *   For searches and help try:
> *
> *
> *

CONFIDENTIALITY NOTE:  This e-mail message, including any  attachment(s),
contains information that may be confidential,  protected by the attorney-
client or other legal privileges, and/or  proprietary non-public
information.  If you are not an intended  recipient of this message or an
authorized assistant to an intended  recipient, please notify the sender by
replying to this message and  then delete it from your system.  Use,
dissemination, distribution,  or reproduction of this message and/or any of
its attachments (if  any) by unintended recipients is not authorized and
may be unlawful.

*   For searches and help try:

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