Announcement

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

  • Removing Those Many Zeroes after Decimals of a variables

    Dear Stata Members
    Consider the variable "income" which has an observation equal to usd140000.0000000007.
    As I mainly use excel for data cleaning, I have many such figures and I want to trim (I don't know whether that is the correct word or not) or CONSIDER ONLY 3 DIGITS after the decimal. I thought of using -round-function but is there any function that can remove all the digits (retaining 3) after decimal

  • #2
    could you type in Stata dataex income in 1/10 and show us the output in the results window?

    Comment


    • #3

      Dear Oyvind Snilsberg. Kindly see the image in SPREADSHEER and in colum B,-13.2 is actually -13.1999999999999. If I import those value into Stata, how will Stata treat it? Will Stata round it off to -13.2 or use -13.199....?If the second is how Stata stores, then I have some issues
      Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	5.5 KB
ID:	1640281

      Comment


      • #4
        Stata will probably treat it as a string but you can convert it to numeric, which should round it off to -13.2, by typing,
        Code:
        destring(variable),replace

        Comment


        • #5
          Most multiples of 0.001 can't be held exactly in binary. 0.500, 0.250, 0.750, 0.125, 0;375, 0.625, 0.875 can; but (e.g.) 0.001 certainly can't, This is often called the problem of precision with many explanations such as

          Blog . . . . . . . . . . . . . . . . . . The penultimate guide to precision
          . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W. Gould
          4/12 http://blog.stata.com/2012/04/02/the-penultimate-
          guide-to-precision/

          Blog . . . . . . . . . . . . . . . . . . . . Precision (yet again), part II
          . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W. Gould
          6/11 http://blog.stata.com/2011/06/23/pre...again-part-ii/

          Blog . . . . . . . . . . . . . . . . . . . . Precision (yet again), part I
          . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W. Gould
          6/11 http://blog.stata.com/2011/06/17/pre...-again-part-i/

          Blog . . . . . . . . . . . . . . . . . How to read the %21x format, part 2
          . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W. Gould
          2/11 http://blog.stata.com/2011/02/10/
          how-to-read-the-percent-21x-format-part-2/


          If you want calculations in any currency to be exact, convert to integers.

          If you want to see (e.g.) 3 decimal places, round() is not the answer, but display format is;

          Comment


          • #6
            Dear Nick Cox thanks for the reply. I have a general question regarding -format-, that it doesn't change the variable but only make the display in a wider format right?

            Comment


            • #7
              Changing a display format at most changes what is displayed. It never changes what is stored, that is, held in a variable, scalar, matrix,. macro or characteristic.

              See https://www.stata-journal.com/articl...article=dm0067 for more.

              Apparent exceptions to this are not changing the display format, but changing or creating a value (or set of values) and using a display format as an argument. For example:

              Code:
              . local show : di %4.3f _pi
              
              . di "`show'"
              3.142
              Last edited by Nick Cox; 10 Dec 2021, 10:49.

              Comment

              Working...
              X