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 <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: SV: How to convert date saved as string in the form of yyyymm
Date
Mon, 30 Dec 2013 03:00:51 +0000
<>
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
[email protected]
On 29 December 2013 21:00, Petter Berg <[email protected]> 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: [email protected] [[email protected]] för David Ashcraft [[email protected]]
> Skickat: den 29 december 2013 21:48
> Till: [email protected]
> Ä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/