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: how to keep number after comma only


From   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: how to keep number after comma only
Date   Tue, 25 Feb 2014 12:13:46 -0500

Nick, what I meant is that Stata is doing something else with mod for
negativess, then it declares, as the following example shows, it is
likely internally calls floor() instead of int() as per documentation:

do "T:\2014\20140225_1207_mod_floor.do"

Best, Sergiy Radyakin

On Tue, Feb 25, 2014 at 12:00 PM, Nick Cox <[email protected]> wrote:
> This crossed with my previous.
>
> -mod(abs(x), 1)- is a modified suggestion.
> Nick
> [email protected]
>
>
> On 25 February 2014 16:53, Sergiy Radyakin <[email protected]> wrote:
>> . local x=-3.1415
>> . di mod(`x',1)
>> .8585
>>
>> . di `x'-floor(`x')
>> .8585
>>
>> Though this is not your case, probably. But I would still put an
>> 'assert (term>=0)' before getting the fraction in a way like this.
>>
>> Also note that Stata defines mod(x,y) as x - y*int(x/y) on domain (-inf;+inf).
>> I don't think it is working for negatives:
>> . di mod(`x',1)
>> .8585
>>
>> . di mod(`x',2)
>> .8585
>>
>> Best, Sergiy
>>
>> On Tue, Feb 25, 2014 at 11:36 AM, Nick Cox <[email protected]> wrote:
>>> The fractional part is the remainder on division by 1.
>>>
>>> . di mod(_pi, 1)
>>> .14159265
>>>
>>> . di mod(3.1,1)
>>> .1
>>>
>>> or the difference between a number and its floor.
>>>
>>> Nick
>>> [email protected]
>>>
>>>
>>> On 25 February 2014 16:24, Dao Kim <[email protected]> wrote:
>>>
>>>
>>> I am trying to keep only the digits of a number, for example 37.1
>>> weeks in order to convert it into days. I could keep the first 2
>>> numbers with "gen long term_days = floor(term/10)", how does it work
>>> for the number after the comma?
>>> *
>>> *   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/
>> *
>> *   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/
> *
> *   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/
*
*   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/


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