Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ceil function for decimals?

    I want to store p-values in macros to display in graph captions and am having trouble with p-values that are nearly zero as the round(p-value, .001) function returns 0, which looks incorrect in the output:

    mgof variablex, mc ksmirnov

    global ksfull=round(r(p_ksmirnov), .001)

    twoway...caption("KS test rejects null, p=$ksfull")

    In many cases I get p=0, where I would prefer to have p<.001. If the ceil() function had the option of specifying digits, as round() does, then this would be trivial. Any suggestions?

    Sean

  • #2
    You have not explained mgof as a user-written program. Please see the FAQ Advice.

    The function round() produces another number, not a string display. Note that round() with second argument 0.001 can at best produce binary approximations to multiples of 0.001.

    You may get closer to what you want with

    Code:
    global ksfull = cond(r(p_ksmirnov) < 0.001, "< .001", string(r(p_ksmirnov), "%4.3f"))

    Comment


    • #3
      Sean, perhaps you could apply scaling/subscaling. Compare:
      Code:
      local precision=0.001
      
      display round(0.0002, `precision')
      display round(0.0008, `precision')
      
      display ceil(0.0002/`precision')*`precision'
      display ceil(0.0008/`precision')*`precision'
      Produces values 0 and 0.001 for round() function and 0.001 and 0.001 for the ceil() function.

      Best, Sergiy Radyakin

      Comment

      Working...
      X