Bookmark and Share

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]

Re: st: Integer values in Stata


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Integer values in Stata
Date   Thu, 1 Sep 2011 11:17:09 +0100

There are naturally other ways to do it. Another is

. keep if mod(end, 1) == 0

or

. keep if !mod(end,1)

Nick

On Thu, Sep 1, 2011 at 11:10 AM, Nick Cox <[email protected]> wrote:
> -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 <[email protected]> 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index