Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: st: Replace missing values by 0

From   "Martin Weiss" <>
To   <>
Subject   AW: st: Replace missing values by 0
Date   Mon, 9 Aug 2010 11:06:27 +0200


Stata even forgives the missing blank after -if-! Amazing!

inp prean pa_kurn
2 3
. 5
. 3
. .
4 5
foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)

One problem with this "first-principles" approach is that you have to
compare explicitly with all missing values, i.e. also the extended ones.
-recode- can help avoid this problem.


-----Ursprüngliche Nachricht-----
[] Im Auftrag von Neil Shephard
Gesendet: Montag, 9. August 2010 11:01
Betreff: Re: st: Replace missing values by 0

On Mon, Aug 9, 2010 at 8:55 AM, Hobst <> wrote:
> I have two variabled called "prean" and "pa_kum" that contain missing
> These missing values i would like to replace by 0 (zero). What command can
> use to do this?

foreach x of varlist prean pa_kurn{
  replace `x' = 0 if(`x' == .)
} one way to skin this cat.

> Thanks in advance for your support. Regards

This is a very basic question though.  You may well benefit from
reading the Users Guide and/or  taking the Stata Net Course 101 :
Introduction to Stata (see


"One should as a rule, respect public opinion in so far as is
necessary to avoid starvation and to keep out of prison, but anything
that goes beyond this is voluntary submission to an unnecessary
tyranny, and is likely to interfere with happiness in all kinds of
ways..." - Bertrand Russell

Email -
Website -
Photos -
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index