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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: MM/DD/YYYY string to stata date


From   Lars Folkestad <lfolkestad@health.sdu.dk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: MM/DD/YYYY string to stata date
Date   Tue, 5 Jun 2012 06:58:55 +0200

Thank you both. 

Nick: i dont want to make it hard for Stata. How do i go from string mm/dd/yyyy to date?

Mvh
Lars Folkestad


Den 05/06/2012 kl. 00.43 skrev "Nick Cox" <njcoxstata@gmail.com>:

> To expand a bit: If you remove the separators, you make it harder for
> Stata. It can deal with dates of the form "ddmmyyyy", "DMY" or
> "ddmmyy", "DMY", "yyyy", but yours don't fit either pattern.
> 
> Nick
> 
> On Mon, Jun 4, 2012 at 9:16 PM, Abhimanyu Arora
> <abhimanyu.arora1987@gmail.com> wrote:
>> I guess it works OK if instead of
>>  gen newstrvar = subinstr(strvar, "/", "", .) you type in
>>  gen newstrvar = subinstr(strvar, "/", "-", .) and then the date function.
>> 
>> On Mon, Jun 4, 2012 at 9:36 PM, Lars Folkestad <lfolkestad@health.sdu.dk> wrote:
>>> Dear list
>>> 
>>> I know this is an old timer but i just dont get it.
>>> 
>>> I have a variable indicating birth date. The variable is in string format and looks like this
>>> 
>>> Mm/dd/yyyy
>>> 
>>> If the the month or day is single digit it looks like this
>>> M/d/yyyy
>>> 
>>> I have removed the /'s by
>>> 
>>> 
>>> gen newstrvar = subinstr(strvar, "/", "", .)
>>> 
>>> But form there i dont get it.
>>> 
>>> Ive used
>>> 
>>> Gen newdate = date (newstrvar, "MDY")
>>> 
>>> But that only gives me missing values.
>>> 
>>> 
>>> What am i doing wrong and is there an easy way to do this?
> 
> *
> *   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