Announcement

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

  • How to reformat the value of the missing values in a variable?

    I have a dataset with an interval variable having various values from -10 to +10. However, sometimes if the data for an observation was not available, they coded it as -99. How can one change the -99 as no value or just a dot? Since there are thousands of observations with missing values of -99, I would be grateful if you provide an idea of how to get away that -99 as a dot. Also, is it possible to create a dummy variable with -99 as a dot, while converting values +1 to +10 as 1 and values -1 to -10 as 0?

  • #2
    -help mvdecode-

    Added: By the way, it's not a matter of changing the "format." The term "format" in Stata refers to the way the number is displayed when you -list- or -browse-, which can be quite different from the actual value of the number that Stata sees and uses in computations. You actually need, in this situation, to change the value of the number from 99 to . ("dot"). That's not a reformatting; that's a replacement or a recoding.
    Last edited by Clyde Schechter; 28 Apr 2017, 23:15.

    Comment


    • #3
      Karthy:
      I do share Clyde's remark abour correct Stata jargon.
      Assuming your variable is numerical (i.e., it is not a -string-), you can type:
      Code:
      replace <yourvar>=. if <yourvar>==-99
      I fail to get the need for a categorical variable reporting missing values (if your intent is to perform an augmented regression using that categorical variable as a predictor for replacing missing values, please note that it usually hampers more than helps). Why don't recoding everything in the same variable?
      Code:
      replace <yourvar>=. if <yourvar>==-99
      replace <yourvar>=0 if <yourvar><0
      replace <yourvar>=1 if <yourvar>>=1 & <yourvar>!=.
      Kind regards,
      Carlo
      (Stata 18.0 SE)

      Comment


      • #4
        Mr. Lazzaro,

        Thank you so much. It worked.

        Comment

        Working...
        X