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 on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: generating year for a given age


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: generating year for a given age
Date   Tue, 4 May 2010 22:56:22 +0200

<>

This is a cheap first shot. You want to dig deeper into -help
dates_and_times- to get all the leap years and stuff into this. Am I correct
that your "dateint" has the first two characters reversed?

***********
clear*

inp byte id str13 dateint age_bl  
 1    "7242003"   81.00753 
 2    "6132003"   89.99042 
 3    "4222004"   84.70363 
 4    "1092005"   71.01163 
 5    "9042003"   65.36345 
end

compress
list, noo

gen str15 newdate= /* 
*/ reverse(substr(dateint,1,2))+ " " + /* 
*/ substr(dateint,3,1)+ " " +substr(dateint,4,.)
gen mydate=date(newdate, "DMY")
form mydate %tdMon_DD,_CCYY
drop dateint newdate

gen birthday=mydate-age_bl*365
format birthday %td
gen yearwhenforty=yofd(birthday+40*365)
l
***********


HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Debs Majumdar
Sent: Dienstag, 4. Mai 2010 22:38
To: statalist@hsphsun2.harvard.edu
Subject: st: generating year for a given age

Hi,

   I have a dataset  where I have the date of interview and the
corresponding age at that time (age_bl). I want to create two variables of
of this: 1) date of birth and 2) year when age was 40 for the participants.

      | id     dateint       age_bl   |
      |--------------------------------------|
  1. |  1    7242003   81.00753  |
  2. |  2    6132003   89.99042  |
  3. |  3    4222004   84.70363  |
  4. |  4   10192005   71.01163 |
  5. |  5    9042003   65.36345  |
     +-------------------------------------+


  How would I do that?
  
  Thanks,
  
   Debs



      

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

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


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