Statalist The Stata Listserver

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

Re: st: decimal years

From   "Austin Nichols" <>
Subject   Re: st: decimal years
Date   Fri, 11 Aug 2006 15:21:15 -0400

I also usually use floor() and I do below for the year calculation
gen y=floor(ev)
--incorrectly, probably, since the date -4.1 should be in 5 BCE, I
suppose, though I always screw up arithmetic in the reign of Augustus.
But the calculation for the day of the year is in the nonnegative
real line, which I wanted to emphasize with the use of int() in the
day-of-year calculation.  But now I have to go read Wikipedia about
what happened in year zero, I think.

On 8/11/06, Nick Cox <> wrote:
I believe all this. My problem was reading Caleb's post literally.

But note that -int()- is dangerous with dates. -int()- rounds
towards zero, and thus does different things
either side of the time origin. This won't bite
you here because your origin, the notional year 0,
is way outside the likely data, but in general -floor()- is better,
especially with Stata's date origin and dates <= 1959.


Austin Nichols

>  clear
>  input double event1
>  1932.288
>  1960.0044
>  end
>  gen y=floor(ev)
>  gen yl=doy(mdy(12,31,y))
>  gen d=int((ev-y)*yl)+1
>  gen nd= mdy(1,1,y)+d-1
>  format nd %d
>  l, noo clean
> My advice about ignoring all the above and instead using the obs# as
> the variable in -tsset obs- stands, however.  In particular, I don't
> believe that 1932.288 is intended to represent April 15, 1932 at
> 9:47:31am, but instead someone took April 14, turned that into the
> 105th day of the year (where 1/1 is the first day) and then divided
> 105 by 365 and rounded to .288, which set of operations is not
> everywhere invertible.  To merely preserve order, I reiterate:
> sort event1
> gen obs=_n
> tsset obs
*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index