Announcement

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

  • set data out of range as missing

    Dear statalist,

    I have a variable, index, its value should be between 0 to 1, but there are some values out of this range, so I want to set those values as .
    I tried
    Code:
    replace index==. if index<0|index>1
    but that doesn't work. replace index=. doesn't work either
    It seems I could replace index with any real value but not .

    Any help will be greatly appreciated!
    Last edited by Lucy Garcia; 29 Dec 2021, 23:26.

  • #2
    You used "==" rather than "=" in your attempt to assign a value to the variable index. "==" is used for comparison of values, and "=" to assign values.

    Comment


    • #3
      Hi Mike,

      Thanks a lot for your quick reply.

      I tried
      Code:
      replace index=. if index<0|index>1
      and it shows
      Code:
      (2,083 real changes made, 2,083 to missing)
      does that mean actually no change has been made?

      I use count if to see how many values are >1 or <0 and the number is still 2083 after I apply the replace command. So what's wrong here?
      Last edited by Lucy Garcia; 29 Dec 2021, 23:39.

      Comment


      • #4
        Missing values are evaluated greater than 1.

        Code:
        assert 0>1
        assert .>1
        Res.:

        Code:
        . assert 0>1
        assertion is false
        r(9);
        
        . assert .>1
        
        .
        Your code worked fine.

        Comment


        • #5
          Thanks Andrew! My bad, I get my head around now!

          Comment

          Working...
          X