Statalist The Stata Listserver


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

st: RE: Changing date of birth to age in data editor


From   <[email protected]>
To   <[email protected]>
Subject   st: RE: Changing date of birth to age in data editor
Date   Tue, 15 May 2007 08:43:27 +0800

Gen today = 15 May 2007
This should read as a string variable

Gen today2 = date(today, "dmy")
This will convert today into elapsed date format

Format today2 %dD_m_Y
This will allow today2 to be shown in the normal way

Then 
Gen age = (today2 - dob)/365.25
This should give you age in years with decimals.

Format age %2.0f if you want age as whole numbers.

I might have missed something - good luck

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Mark Slatyer
Sent: Tuesday, 15 May 2007 07:46
To: [email protected]
Subject: st: Changing date of birth to age in data editor

Dear Statists,

Could anyone tell me how to change a data set with dob to present age as
a
new variable please.


Mark Slatyer


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index