Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: imputing dates into a string date


From   Steve Nakoneshny <[email protected]>
To   "[email protected]" <[email protected]>
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" <[email protected]> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index