Announcement

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

  • change variable attributes by its own mean?

    Hei, I have a variable that has "(1) Strongly disagree; (2) Disagree; (3) Neither agree nor disagree; (4) Agree; (5) Strongly agree (99) I don't know"...... I would like to change 99 with the variable's own mean. how is the formula for achieving this? thank you!

  • #2
    Code:
    summ var, meanonly
    replace var = `r(mean)' if var == 99

    Comment


    • #3
      Building on Clyde's code, I think you want
      Code:
      summ var if var != 99, meanonly
      replace var = `r(mean)' if var == 99
      although I would be more likely to do the following
      Code:
      mvdecode var, mv(99)
      clonevar var_m = var
      summ var_m, meanonly
      replace var_m = `r(mean)' if missing(var_m)
      I start by replacing the "don't know" with a Stata missing value, precisely to avoid accidentally using "99" in a calculation. Then, instead of changing that variable, I create a new variable with the mean substituted for the missing values. You now have your original variable, and the variable with the mean substituted. Each will be useful in different circumstances.

      Comment


      • #4
        Thank you all !

        Comment

        Working...
        X