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

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Integer values in Stata |

Date |
Thu, 1 Sep 2011 11:10:47 +0100 |

-int(end)- is not a true or false test of whether its argument is integer. Rather it rounds towards zero, and the result is an integer: if that result is non-zero if it is treated as true. That explains why you got what you did. keep if end == int(end) is one way of selecting integers as values that are already integers are unchanged by the function. A similar example is already included in my talk for the London users' meeting on functions. Nick On Thu, Sep 1, 2011 at 11:02 AM, Tim Evans <Tim.Evans@wmciu.nhs.uk> wrote: > I have a list of values in a column in Stata like so: > > end > .2 > .4 > .6 > .8 > 1 > 1.2 > 1.4 > 1.6 > 1.8 > 2 > 2.2 > 2.4 > 2.6 > 2.8 > 3 > 3.2 > 3.4 > 3.6 > 3.8 > 4 > 4.2 > 4.4 > 4.6 > 4.8 > 5 > > and I wish to only keep the whole number value i.e. 1,2,3,4,5 etc. and drop any non integer values. I there use the following code > > keep if int(end) > > however, I still end up with the following values > > end > 1 > 1.2 > 1.4 > 1.6 > 1.8 > 2 > 2.2 > 2.4 > 2.6 > 2.8 > 3 > 3.2 > 3.4 > 3.6 > 3.8 > 4 > 4.2 > 4.4 > 4.6 > 4.8 > 5 > How do I ensure I only keep the whole numbers? Using the following would not be ideal (keep if inlist(end, 1,2,3,4,5)) as I may have a much longer list. * * 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/

**Follow-Ups**:**Re: st: Integer values in Stata***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**Re: st: Polynomial Fitting and RD Design***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Polynomial Fitting and RD Design***From:*Maarten Buis <maartenlbuis@gmail.com>

**Re: st: Polynomial Fitting and RD Design***From:*Nick Cox <njcoxstata@gmail.com>

**Re: st: Polynomial Fitting and RD Design***From:*Maarten Buis <maartenlbuis@gmail.com>

**st: Integer values in Stata***From:*Tim Evans <Tim.Evans@wmciu.nhs.uk>

- Prev by Date:
**st: Integer values in Stata** - Next by Date:
**Re: st: Integer values in Stata** - Previous by thread:
**st: Integer values in Stata** - Next by thread:
**Re: st: Integer values in Stata** - Index(es):