Announcement

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

  • replace multiple variables at the same time

    Hi, I have 10 variables. All of these variables are dummy, 0 or 1. The original data set is 1 and . in other words, 0 values are denoted as missing (no input).

    I know a basic and silly method is:

    Code:
    replace var1 = 0 if var1 == .
    And writing down this code 10 times for different var.

    Is there any cool method?

  • #2
    Well, on the assumption that your variable names are var1, var2, …, var10, and they are located consecutively in your data set you can do:

    Code:
    mvencode var1-var10, mv(0)
    If those aren't the names of your variables, then list out the variables individually, or, if possible, abbreviate the list using wildcards.

    Also, to avoid glitches like this on the Forum, in the future always show example data, using -dataex-, when you ask for help with code. That way nobody has to guess what your variable names are.

    All of that said, why do you want to do this? It is usually not a good idea in Stata to use some numeric code (whether 0 or anything else) to denote no input. Missing values work very well in Stata for that purpose and should usually be left as missing values. And substituting numeric codes for the missing values usually will get you in trouble down the road. So unless you have a compelling reason to do this, I suggest you not do it.

    Yes/No variables are best coded as 1/0, and 1/. will get you in trouble.
    But using 0 to denote "didn't respond" or "unknown" is a bad idea. That's what missing values are for.

    Comment


    • #3
      Thank you, Clyde.

      It's Yes/No variable. The reason for missing in the dataset is that they researcher just left blank for all "no" answers.

      Comment


      • #4
        OK, got it. Thanks.

        Comment

        Working...
        X