Announcement

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

  • replacing missing values with zeros

    Hi,

    I use STATA 13SE. My dataset has missing values in more than 15 variables (they are newly generated variables) and I need to replace them by zeros. Is there any command I can use to just input zeros whenever value missing, without having to specify varlist?

  • #2
    Code:
     mvencode _all, mv(0)
    should do it, though I question the wisdom of doing so.

    Comment


    • #3
      Exactly why do you need to replace missings by zero? The only circumstance I know of where this is justified is when answers are missing because of a skip pattern in a questionnaire. If, for example, the answer to a question "Do you smoke cigarettes" is "No", all further questions related to cigarette smoking are skipped. This includes a question about the "number smoked per day", which for non-smokers is zero.

      Please also note the strong preference on Statalist for full real names on Statalist, a long-standing practice that contributes to professionalism and collegiality on the list. Please re-register with a username that includes your full names, first and last; use the Contact Us button on the bottom of the page.
      Steve Samuels
      Statistical Consulting
      [email protected]

      Stata 14.2

      Comment


      • #4
        Thank you for your assistance. Actually, I am not completing zeros for survey data. I should have explained in more detail what I was doing, but here it is. This is national level data for dummies that code religions with more than 7% pop/country. If rel<7%pop, STATA uses missing value. After that, I generated a new var (relfraction) that adds up number of religions with at least 7%pop, but STATA could not add with missing values. I used mvencode _all, mv(0) and this worked well. Thank you Ben Earnhart. I am gonna try to modify the username.

        Comment


        • #5
          Steve is absolutely on target, and Ben's warning is also correct.

          Indeed, your explanation of why you want this is not at all clear. Stata [N.B. not "STATA"] typically ignores missing values when summing. If you (think you) are experiencing different behaviour you should tell us exactly what commands you are using and why you say what you did.

          Moreover, you now have to watch out with whatever you do with those variables, as Stata retains no memory that the zero values really should be missing here. If you had real zeros beforehand, things are even more confused.

          Comment


          • #6
            Hi Nick Cox. Indeed, but I went just instrumental in constructing these dummies. I guess there is some other more efficient way to generate dummies without using long commands (i.e. one for generating dummy =1, other for replacing missing with zeros). Thank you all for the recommendations. Very useful post for me!

            Comment


            • #7
              Code:
               
              gen indicator = <true_or_false_condition>
              will do what you want in one line. See e.g. http://www.stata.com/support/faqs/da...lse/index.html

              Comment

              Working...
              X