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: on converting dates in stata


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: on converting dates in stata
Date   Sun, 4 Sep 2011 01:29:46 +0100

Another way to do it

ym(floor(date1/100), mod(date1,100))

On Sun, Sep 4, 2011 at 12:36 AM, Phil Clayton
<[email protected]> wrote:

> Not sure if this is the most efficient, but I would:
> 1. convert it to a string
> 2. convert the string to a "day" format date using the date() function
> 3. convert the "day" format date to a "month" format date using the mofd() function
>
> You can do all of the above in a single line. Example:
>
> input date1
> 200601
> 200602
> 200603
> 200604
> end
>
> gen date2=mofd(date(string(date1), "YM"))
> format %tm date2
> list
>
> Phil
>
> On 04/09/2011, at 6:24 AM, [email protected] wrote:
>

>> I have monthly dates in excel in the following form:
>>
>>
>> 200601
>> 200602
>> 200603
>> 200604
>> ...
>>
>> I upload it in Stata and it appears numeric. I have tried a few options with the date command - but I was unsuccessful in converting the variable in the correct formt (mmyyy).
>>
*
*   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