<>
. g strdate=string(var1,"%19.0f")
. l
+----------+
| strdate |
|----------|
1. | 20090102 |
2. | 20090107 |
3. | 20090112 |
4. | 20090126 |
+----------+
. g numdate = date(strdate,"YMD")
. format numdate %td
. g year = yofd(numdate)
. g month = month(numdate)
. g day = day(numdate)
. g week = week(numdate)
. g dow = dow(numdate)
. l
+--------------------------------------------------------+
| strdate numdate year month day week dow |
|--------------------------------------------------------|
1. | 20090102 02jan2009 2009 1 2 1 5 |
2. | 20090107 07jan2009 2009 1 7 1 3 |
3. | 20090112 12jan2009 2009 1 12 2 1 |
4. | 20090126 26jan2009 2009 1 26 4 1 |
+--------------------------------------------------------+
try -help dates and times-
Kit Baum | Boston College Economics & DIW Berlin | http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming
| http://www.stata-press.com/books/isp.html
An Introduction to Modern Econometrics Using Stata | http://www.stata-press.com/books/imeus.html
*
* 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/