Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: removing decimals


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: removing decimals
Date   Thu, 23 Jan 2003 17:09:26 -0000

Laura Miller
> 
> I have calculated a variable which is the age of a subject 
> when they were 
> interviewed. However this variable has several decimal 
> places. I wish to change 
> this to the whole number of years. I have tried using 
> 
> format varname %2.0f 
> 
> but as the manuals state this doesn't affect the accuracy 
> so some of the ages 
> are rounding up. I only want complete years so need to 
> round them all down (or 
> looking at it another way, I just need to 'cut off' the 
> decimal points). Could 
> anyone tell me how can I do this?
> 

Several people rightly suggested -int()-. 

Of interest here -- and in related problems -- 
is the introduction in Stata 8 of -floor()- 
and -ceil()- (ceiling) functions. For ages, 
-floor()- and -int()- will agree, but one 
small point is that the floor and ceiling 
terminology for rounding down and up -- 
due to Kenneth E. Iverson in the early 1960s -- 
is easy to learn and remember, especially if you 
have not memorised _exactly_ what -int()- 
does. 

Nick 
[email protected] 

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