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: Convert to stata date - stored as a numeric variable
From
Joe Canner <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: Convert to stata date - stored as a numeric variable
Date
Thu, 12 Sep 2013 12:46:16 +0000
David,
Try:
. gen date2=date(string(date,"%8.0f"),"YMD")
As per a recent thread, you could also use Nick Cox's -todate-.
Your questions have to do with some fairly basic Stata date and string functions. You should review the Stata help for these functions, as you will likely find many of them very helpful in daily practice.
Regards,
Joe Canner
Johns Hopkins University School of Medicine.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of David Ashcraft
Sent: Thursday, September 12, 2013 2:54 AM
To: [email protected]
Subject: Re: st: Convert to stata date - stored as a numeric variable
Thanks Nick,
I have recoded as per your advice:
gen date2=date(date,"YMD")
generate date1= qofd(date2)
format date1 %tq
I am getting the following response:
gen date2=date(date,"YMD")
type mismatch
This may be due to the format of date variable. As I mentioned the date variable is numeric not string. what do you recommend?
Regards
David
----- Original Message -----
From: Nick Cox <[email protected]>
To: "[email protected]" <[email protected]>
Cc:
Sent: Thursday, September 12, 2013 9:34:55 AM
Subject: Re: st: Convert to stata date - stored as a numeric variable
Your date looks like YMD to me which is what to feed to -date()-. If it is really quarterly you need -qofd()- not -mofd()-.
On 12 Sep 2013, at 06:44, David Ashcraft <[email protected]>
wrote:
> Hello everyone,
>
> My date variable is stored as numeric (double %8.0g). Date format is
> 20121231 i.e. YYYYMMDD. Stata does not read it as a date. I have tried
> the following but it seems that I am missing something.
>
> gen date2=date(date,"MDY")
> generate date1= mofd(date2)
> format date1 %tm
>
> Although my data is quarterly but to be on the safer side I am
> formatting it as %tm.
> Any help will be greatly appreciated.
>
>
> David Ashcraft
> PhD Candidate
> Bangor University
> Bangor, UK.
>
>
> *
> * 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/
*
* 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/