Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: how does one automatically calculate the age in years by subtracting the system date from the date of birth?


From   Gwinyai Masukume <parturitions@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: how does one automatically calculate the age in years by subtracting the system date from the date of birth?
Date   Sun, 10 Mar 2013 14:39:05 +0200

Hi stata list,

I’m using STATA 12.1 and would like to calculate a person’s age. I’m
generating ‘synthetic’ dates drawing from the uniform distribution as
below:

gen month_dob=int(1+(13-1)*runiform())
gen day_dob=int(1+(32-1)*runiform())
gen year_dob=int(1964+(1999-1964)*runiform())
gen date_of_birth=mdy(month_dob, day_dob, year_dob)
format date_of_birth %d
di date_of_birth

I’m able to obtain the current system/stata date by:
gen today_date=c(current_date)
di today_date

Theoretically subtracting the today_date from date_of_birth should
give the age, I’m encountering some problems subtracting these two
dates. Could this be due to date formats i.e. month day year (MDY)
versus day month year (DMY). Or it could be due to one date being an
integer and the other a string? Or it's something else?

Please assist.
Kind regards
G

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index