Announcement

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

  • STATA is calculating wrong

    Hi people, I have a panel data set with persid's with 8 digits.
    Can it be that STATA doesn't take it exact by the pers IDs?
    I have used the following command: by persnr, sort: gen zeilepers = _n
    Sometimes it counts 1 and 2 besides the person numbers are only correct in the first thre digits....? any tips about that to makee stata exact? because this is very important vor my ID based calculations.....

  • #2
    Please read the manuals regarding variable types and precision, and also search the Forum for previous posts on how to hold ID numbers. Are you holding your ID variables as doubles, longs or floats? I suspect the last of these. If so, that'll likely explain the behaviour you observe. Stata is not doing any wrong calculations; it's working with the data in the form that you have given to it. (NB note spelling of "Stata" -- see the FAQ on this.)

    Comment


    • #3
      You don't give a concrete, reproducible example of what is "wrong", but at guess you have some very big identifiers so that float is not a suitable data type.

      Consider whether persnr is the wrong data type.

      You may need to read the data in again with persnr as double or long or even a string equivalent.

      Please study

      Code:
      help data types
      http://www.statalist.org/forums/help#stata

      http://www.statalist.org/forums/help#realnames

      http://www.statalist.org/forums/help#spelling

      Comment


      • #4
        It is in long format-
        storage display value
        variable name type format label variable label
        ---------------------------------------------------------------------------------------------------------------
        persnr long %12.0g persnr

        Comment


        • #5
          So you need to give us an example of what is wrong:

          data in

          code to produce

          results out

          Perhaps you need a double.

          What is the largest persnr?
          Last edited by Nick Cox; 14 Feb 2017, 08:52.

          Comment


          • #6
            Ok, it goes to 9 digits, you are right i used : recast double persnr.......just looking over the first 5000 observation of my 50000 subsample out of 9million data it seems to look correct. Thank you very much.

            Comment


            • #7
              Not quite.

              1. As I understand it, a long should suffice for 9 digits.

              2. Conversely, if you recast double, the recast can't restore the details that were mangled previously. There is no memory of the original data.
              You may need to read them in again.

              Comment

              Working...
              X