Mark Slatyer wrote
Could anyone tell me how to change a data set with dob to present age as a
new variable please.
--------------------------------------------------------------------------------
If you're willing to accept noninteger ages, then the code below will work.
You'll need to make the necessary changes in order to accommodate your
date-of-birth variable's datatype and date format.
If you need age in years as an integer, then it isn't quite as
straightforward. (See http://support.sas.com/ctx/samples/index.jsp?sid=271
for the algorithm.) You'll be able to use Stata's other date functions for
this, e.g., -day()-, -month()-, -year()-. See -help date functions-.
Joseph Coveney
set obs 1
generate str dob = "1960-01-01"
generate float age = (date("`c(current_date)'", "dmy") - ///
date(dob, "ymd")) / 365.25
list
exit
*
* 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/