Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: imputing dates into a string date


From   Steve Nakoneshny <scnakone@ucalgary.ca>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: imputing dates into a string date
Date   Thu, 7 Jun 2012 08:19:49 -0600

Tim,

In an attempt to preempt Nick, you might want to have a look at string functions, particularly -subinstr-. For a practical example, look at the archives from the last week where similar issues have come up (one of which was mine, in fact).

For the record, I probably would have approached this using -regexm- machinery as well, but there's no need to do so if string functions can do the same.

Steve

Sent via carrier pigeon

On Jun 7, 2012, at 7:22 AM, "Tim Evans" <Tim.Evans@wmciu.nhs.uk> wrote:

> Hi all,
> 
> I have dates in the form DMY in a string variable 
> 
> i.e. 22/01/2010
> 
> I am generating numerical dates using the following code:
> 
> generate double dx2 = date(dx, "DMY")
> format %tdDD/NN/CCYY dx2
> 
> This is working fine, until I come across a date that actually starts like this:
> 
> xx/01/2010
> 
> Then my code to generate a date returns a blank. What I would like to do is add in something that allows me to evaluate whether the day is xx and if so, insert 01.
> 
> Am I to assume I need something like regexm 
> 
> 
> 
> if regexm(dx2, "^XX") == 1
>    replace"XX" = 01
> 
> else 
> generate double dx2 = date(dx, "DMY")
> format %tdDD/NN/CCYY dx2
> 
> 
> If you have any ideas, that would be great.
> 
> _DISCLAIMER:
> This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index