Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: splitting a value from its dps! Calculating age from its value with decimal points

 From Nick Cox To "statalist@hsphsun2.harvard.edu" Subject Re: st: splitting a value from its dps! Calculating age from its value with decimal points Date Thu, 5 Dec 2013 12:01:26 +0000

```Note also that that Stata supports monthly dates. In this case, you
need not worry about the origin, because ages as differences are the
same whatever the origin.

So, using also Daniel's suggestion of -floor()-

g age = floor((ym(year_interview, int_month) - ym(yrbirth, monthbirth)) / 12)

Using commas to separate integers from fractional parts is naturally
one of several conventions.

Nick
njcoxstata@gmail.com

On 5 December 2013 11:15, Raffaele Palladino
> 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!

*
*   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/
```