Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Debs Majumdar <debs_stata@yahoo.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: RE: generating year for a given age |
Date | Tue, 4 May 2010 14:18:29 -0700 (PDT) |
Thanks. And I am going to look into the date_and_times just to be thorough when generating then new variables. Yes, you are correct about the reverse characters. Debs ----- Original Message ---- From: Martin Weiss <martin.weiss1@gmx.de> To: statalist@hsphsun2.harvard.edu Sent: Tue, May 4, 2010 1:56:22 PM Subject: st: RE: generating year for a given age <> 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/ * * 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/