Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: decimal years


From   Jeph Herrin <junk@spandrel.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: decimal years
Date   Fri, 11 Aug 2006 08:04:02 -0400

If your variable is -date-, the only tricky part is getting
the number of days in the year. Try:

gen year = round(date,0)
gen daysinyear=mdy(1,1,year)-mdy(12,31,year)
gen day = round((date-year)*daysinyear,0)
gen newdate=mdy(1,1,year)+day

Then -newdate- should contain the date in Stata's elapsed date format.

HTH,
Jeph



Caleb Southworth wrote:
How can decimal years be read into stata? The data are %9.4f and identify
year, month and day, for example

event1
1932.2880
1949.0410
1939.4270

I would like to be able to extract the mdy and to be able to tsset my
data, the latter requiring integers.

Caleb
caleb@uoregon.edu
University of Oregon Sociology
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index