Announcement

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

  • Why is round() not working?

    I try to round a variable and use gen y=round(x, 0.05).

    But the results are not at all what I want and I don't know why.
    For instance, 878.784672 gets 878.79999, or 995.4707 gets 995.45001 etc.


    In some cases it does it correctly but in most cases not. What's the reason or what is the correct command to round if it's not round()?

    Thanks for your help,
    Bobby

  • #2
    At Stata's command line, type
    Code:
    help precision

    Comment


    • #3
      ok thanks, so I just have to add double, like gen double y=round(x, 0.5).

      Comment


      • #4
        I have seen users ask about the behavior of round() when their purpose was to get a nicer display of the values of a variable. If this applies in your situation, you would likely find the -format- command useful, e.g.: format x %8.3f

        Comment

        Working...
        X