Announcement

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

  • Deleting Negative Values in a Variable

    Stata Experts:
    I am working with a dataset that has several variables. Each of these variables contain lists of numerical values. I would like to delete those values that are ==-9 as that indicates data that was "not ascertained" by the interviewer. Can I do this in one step with some kind of loop or do I need to delete these values from each individual variable . I appreciate your help.
    Regards,
    Pat

  • #2
    You can delete observations or change values in a variable. Deleting values makes no sense unless you delete the entire observation. I guess you want the second, and need to look at

    Code:
    help recode

    Comment


    • #3
      Thank you. Yes, I would like to keep the observation, but drop those values that are ==-9. I have been using the command . drop if VAR==-9 for each variable. I will look at recode instead.

      Comment


      • #4
        is "-9" a code indicating missingness? if yes, see
        Code:
        help mvdecode

        Comment


        • #5
          Thank you!
          In my dataset there are two codes:
          -9 relates to "not ascertained" i.e. (during an interview)
          ". " missing (respondent failed to answer an entire section of a survey)
          The number of -9 values for each variable is small relative to the distribution for that variable
          I could recode -9 to "." as Nick suggested versus dropping values=-9

          Comment


          • #6
            if you want to have more than one missing value each noting a different type of missingness you can; see
            Code:
            help missing
            this can all be done with -mvdecode-; so see
            Code:
            help mvdecode

            Comment


            • #7
              If drop means the drop command there are two (and only two) choices, drop entire variables (columns, for those using spreadsheet speak) or drop entire observations (rows). There is no scope to drop individual values otherwise, so no equivalent of an empty cell unless your variable is string, not the case here.

              I would recode -9 to .a to keep them distinct from what is already missing.

              Comment


              • #8
                Thank you both!

                Comment

                Working...
                X