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]

st: RE: changing date format


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
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: [email protected]
[mailto:[email protected]] On Behalf Of Mike Kim
Sent: Sonntag, 5. September 2010 04:12
To: [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index