Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: Leap years in computing age

From   Stata Chris <>
Subject   st: Leap years in computing age
Date   Wed, 26 Oct 2011 13:35:54 +0200

Hi Listers,

I would like to compute people's precise age in years on the day of an
important event.
Since I use the age as the forcing variable for an RDD, it is
important that I compute it as precisely as possible. In particular, I
want get it right whether individuals have or have not passed the
threshold number of years.

I have both the event day and the day of birth in Stata format, i.e.
in days after 1 January 1960.
Now I reckon I cannot just compute --gen age =
(eventday-birthday)/365--because of leap years.
So my approach was the following:

gen Age_years = year(eventday)-year(birthday)
gen Age_days  = doy(eventday) - doy(birthday)
gen age       = Age_years + Age_days/365
drop Age_*

But I'm wondering whether there is a more straightforward approach to
this, and indeed whether the above approach is correct?

Any suggestions welcome. Thanks a lot, Chris
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index