Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: changing date format


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: changing date format
Date   Sun, 5 Sep 2010 10:50:08 +0200

<>

"Is there any way I can change tradedate into Stata date format without
using
excel?"


Even if you disregarded Michael`s advice and wanted to stick to your
splitting strategy, there is no need for external software:

***********
clear*

inp str8 tradedate
20010102
20010103
20010104
20010105
20010106
20010107
end

gen day=substr(tradedate,-2,.)
gen month=substr(tradedate,5,2)
gen year=substr(tradedate,1,4)
destring  day month year, replace

gen date=mdy(month,day,year)
format date %td

l
***********


HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Mike Kim
Sent: Sonntag, 5. September 2010 04:12
To: statalist@hsphsun2.harvard.edu
Subject: st: changing date format

Dear Statalisters,

I imported daily stock data from CRSP. The data shows date like this:

tradedate
20010102
20010103
20010104
20010105
20010106
20010107
......

Neither of the following commands works: 
- format tradedate %td
- gen date=date(tradedate, "MDY")

I split tradedae into month, day, year in excel, imported into Stata, and
used the following command to combine them. 
- gen date=mdy(month,day,year)

Is there any way I can change tradedate into Stata date format without using
excel?

Thank you in advance,
Mike.


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

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index