Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Raffaele Palladino <palladino.raffaele@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: splitting a value from its dps! Calculating age from its value with decimal points |
Date | Thu, 5 Dec 2013 11:15:45 +0000 |
Hello, I had to calculate my age starting from age and month of the present (interview) and age and month of the birth So basically I first calculated the age in months g age_in_months = ( year_interview- yrbirth)*12+ int_month- monthbirth then I converted the age in years g age_in_years = age_in_months/12 but then it gives me the right age but with dps! I cannot just set the number with 0 dp because for age doesn’t work so! If someone has 20.6 years it is still 20 years while the program would convert it in 21! I cannot use substring because most of the values have 2 positions before the comma (<99 years) but then few others are aged more than 100 yo (so it is three). So basically I need to split the number and get only the part before the comma.. how to do that? I am sure it is quite easy but somehow internet was not very useful this time! any advice, thank you very much! * * 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/