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   Tim Evans <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   RE: st: Integer values in Stata
Date   Thu, 1 Sep 2011 11:23:07 +0100

Thanks Nick all worked a treat.

Best wishes

Tim

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 01 September 2011 11:17
To: [email protected]
Subject: Re: st: Integer values in Stata

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/

_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.


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