Announcement

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

  • Replace not replacing

    Dear Folks,

    Using Stata 15.1.

    When replacing, Stata is declaring that 134 real changes are made, however when I browse or tab the changes, Stata declared "no observations" (see below, for example). I'm a little lost here. Thanks in advance for your help. Code as follows:

    . replace coicop10b=111005099 if inlist(coicop10,111005001,111005003,111005005,1110 05006,111005098,111005099)
    (134 real changes made)

    . tab interview__key if coicop10b==111005099
    no observations

    Best,
    Mike

  • #2
    replace did replace, but not as you wanted.

    This is almost certainly a precision problem. You don't give a data example (FAQ Advice #12) but the problem can be guessed from output like this:


    Code:
    . clear
    
    . set obs 1
    number of observations (_N) was 0, now 1
    
    . gen foo = 111005099
    
    . format %9.0f foo
    
    . list
    
         +-----------+
         |       foo |
         |-----------|
      1. | 111005096 |
         +-----------+
    
    . gen long bar = 111005099
    
    . format %9.0f bar
    
    . list
    
         +-----------------------+
         |       foo         bar |
         |-----------------------|
      1. | 111005096   111005099 |
         +-----------------------+
    There aren't enough bits in your variable, presumably a float, to hold large integers of that magnitude exactly. You need a long type for coicop10b

    Comment


    • #3
      SOLVED

      Dear Folks, I've sorted this out.

      variable coicop10 is a double while variable coicop10b is a float. I solved by: recast double coicop10.

      Thank you.

      Best,
      Mike

      Comment


      • #4
        #3 No, as recasting a double as a double changes nothing.

        Also, recasting a float as a double will not restore detail lost.

        You need not only a storage type fit for purpose, but to repeat all calculations producing the new variable.

        Comment


        • #5
          Dear Nick

          Thank you and indeed, I omitted to state this. I recasted a float as a double before I replaced.

          Thanks again,
          Mike

          Comment

          Working...
          X