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, **statalist.org** is already up and running.

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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
AW: st: Replace missing values by 0 |

Date |
Mon, 9 Aug 2010 17:28:09 +0200 |

<> ************* replace `x' = 0 if (`x' >= .) ************* might also do the trick. It is important, in all solutions offered in this thread, to make sure you feed them only numeric variables. Nick`s -mi()- function does cover strings as well, but the first part of the -replace- command is then no longer correct. HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Nick Cox Gesendet: Montag, 9. August 2010 17:20 An: statalist@hsphsun2.harvard.edu Betreff: RE: st: Replace missing values by 0 Should be replace `x' = 0 if missing(`x') Nick n.j.cox@durham.ac.uk -----Original Message----- From: Nick Cox I have one specific and one general comment here. Specifically, Martin is correct to underline that . is not the only missing value, but the loop in question is easily fixed by foreach x of varlist prean pa_kurn{ replace `x' = 0 if missing(x) } Generally, a minimal -search missing- points to several resources. One of the very first entries, to [I] missing values, answers this question comprehensively, so it is difficult to see why it was felt necessary to send it to Statalist. Nick n.j.cox@durham.ac.uk Martin Weiss ============ Stata even forgives the missing blank after -if-! Amazing! ************* clear* inp prean pa_kurn 2 3 . 5 . 3 . . 4 5 end foreach x of varlist prean pa_kurn{ replace `x' = 0 if(`x' == .) } l ************* 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. Neil Shephard ============= foreach x of varlist prean pa_kurn{ replace `x' = 0 if(`x' == .) } ...is one way to skin this cat. Martin Weiss ============ clear* input myvar 1 3 5 . 3 6 7 end recode myvar (mis = 0) l Tirthankar Chakravarty -mvencode- Tobias Friedli > I have two variabled called "prean" and "pa_kum" that contain missing values. > These missing values i would like to replace by 0 (zero). What command can i > use to do this? * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Replace missing values by 0***From:*Hobst <tobias.friedli@access.uzh.ch>

**Re: st: Replace missing values by 0***From:*Tirthankar Chakravarty <tirthankar.chakravarty@gmail.com>

**RE: st: Replace missing values by 0***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**RE: st: Replace missing values by 0***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**RE: st: Replace missing values by 0** - Next by Date:
**Re: st: lpoly and nonmissing fitted values where the dependent variable is missing** - Previous by thread:
**RE: st: Replace missing values by 0** - Next by thread:
**Re: st: Replace missing values by 0** - Index(es):