Announcement

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

  • Cleaning data

    Hi, first post on stata forum here: Hello. I have a survey dataset with lots of -5, -4, -3, -2, -1 for failed surveys (not at home, unanswered etc). How do I replace those numbers with missing values so that when I average over them with Collapse they won't register as zeros.

  • #2
    Code:
    mvdecode * , mv(-5=.a \ -4 = .b \ -3 = .c \ -2 = .d \ -1 = .e)
    Will change the value -5 till -1 to missing values for all variables in your dataset. If you only want to change them for some, but not all, you can specify them instead of *. There are lots of tricks to make that specification easier discussed in help varlist.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Gordon, just to clarify Maarten's post a bit, . is the general missing value. Stata also recognizes a number of what we call extended missing values, denoted by .a through .z. Those are precisely for the sort of situation where something is missing for different reasons, e.g. not at home, not answered, subject abducted by aliens, etc. You could simply replace them with . if you don't think you'll need the extended missing info. For the most part, the extended missing responses are treated the same way as misssing, unless you use tabulate with the , missing option.
      Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

      When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

      Comment


      • #4
        Dear Colleagues, thank you very much. Someone else suggested doing it as a loop

        local xlist
        foreach v of varlist `xlist' {
        replace `v'=. if `v'<0
        }

        But a general command is excellent!

        Comment

        Working...
        X