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: How to replace a missing date with value?


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: How to replace a missing date with value?
Date   Mon, 21 Jan 2013 17:09:21 +0000

Let me add how I approach questions like this. Let me also confess
that I didn't see problem 1 immediately. Problem 2 was more evident.

I always want to get quickly to specific examples with problems like
this to test my understanding, so -display- is my friend

. di date("29-02-2001","DMY")

and it returns missing. So why? The date looks well-formed with no
ambiguity about century, which often bites with -date()-. Wait, it's
29th February and ...

Also, just staring at the code is often not active enough. Often you
have to be more active: check examples, check what should be true,
etc.

Nick

On Mon, Jan 21, 2013 at 5:01 PM, Nick Cox <[email protected]> wrote:
> There are two problems with your code.
>
> 1. Your first -replace- asks for a replacement of the date with the
> -date()- equivalent of 29 February 2001. But 2001 was not a leap year,
> so there was no 29 February that year, so Stata returns missing, and
> nothing is changed.
>
> 2. Your second -replace- has exactly the same problem, plus the fact
> that what you have supplied is not a DMY argument, but a MDY argument.
>
> So, it seems likely that whatever leads you to apply 29 February is
> wrong in this case.
>
> Nick
>
> On Mon, Jan 21, 2013 at 4:53 PM, Kanter, Rebecca <[email protected]> wrote:
>
>> I am trying to replace date value that was missing (.) with the actual value that I now have.
>>
>> Given that date1 is a date (DMY) variable in %dM_d,_CY format..
>>
>> I do not understand why the below code does not result in the requested change to change date1==. (MISSING) to date1=29feb2001
>>
>> replace date1 = date("29-02-2001","DMY") in 23 (via edit)
>> (0 real changes made)
>>
>>  replace date1 = date("02-29-2001","DMY") if  id=="12345" (via command screen)
>> (0 real changes made)
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index