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: SV: How to convert date saved as string in the form of yyyymm


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: SV: How to convert date saved as string in the form of yyyymm
Date   Mon, 30 Dec 2013 09:59:32 +0000

<>

For more discussion, see
http://www.stata-journal.com/article.html?article=dm0067

Nick
njcoxstata@gmail.com


On 30 December 2013 03:00, Nick Cox <njcoxstata@gmail.com> wrote:
> <>
>
> Petter's specific advice is good.
>
> The reason why: -date()- is not a generic function for producing any
> kind of date. It produces _daily_ dates only. This is documented at
> -help dates and times-.
>
> In any case, "ym" is an invalid argument unless David is using an old
> version of Stata (Stata 9 back to whenever -date()- was introduced),
> which he should have told us about).
>
> I glanced quickly at the Stanford document Petter mentioned. On p.2 it
> talks about date-time formats as variable types. That conflates two
> distinct concepts, display format and variable type. This is a common
> confusion, but it's a confusion nevertheless. It leads to people
> trying to convert from one kind of date variable to another by
> changing the format, which is doomed to failure.
>
> I'm happy to guess that the rest of the document is mostly accurate,
> but I'd recommend reading the official Stata documentation if you seek
> an authoritative account.
> Nick
> njcoxstata@gmail.com
>
>
> On 29 December 2013 21:00, Petter Berg <pbe@copenhageneconomics.com> wrote:
>> Hi David,
>> gen date= monthly(your_var,"YM")
>> format date %tm
>>
>> should do the trick.
>>
>> See this excellent Stanford tutorial for further questions on dates
>> https://www.stanford.edu/group/ssds/cgi-bin/drupal/files/Guides/Working%20with%20Dates%20and%20Times%20in%20Stata.pdf
>>
>> Best,
>> Petter
>> ________________________________________
>> Från: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] f&#246;r David Ashcraft [ashcraftd@rocketmail.com]
>> Skickat: den 29 december 2013 21:48
>> Till: statalist@hsphsun2.harvard.edu
>> Ämne: st: How to convert date saved as string in the form of  yyyymm
>>
>> I have monthly panel data for which date is a string  variable in the format 2013m1. Now I want to convert this date into stata readable date format. I tried following:
>>
>> gen date2 = date(date, "ym")
>> (133566 missing values generated)
>>
>> or
>>
>> gen date2 = date(date, "yyyymm")
>>
>> results are same for both. Can anyone please help me resolve this.
>> Regards
>>
>> David Ashcraft
>> PhD Candidate
>> Bangor University
>>
>> *
>> *   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/
>>
>> *
>> *   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/

*
*   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