Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: na.omit synonym


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: na.omit synonym
Date   Wed, 20 Jun 2007 10:39:36 -0400

Matthias--
Suppose you store all the relevant variables in a -local- varlist, e.g.
sysuse auto, clear
ds mpg-headr
local varlist `r(varlist)'

Neil offered the command
mvdecode `varlist', mv(-1)
and suggested a loop over variables to drop any missings, while Kit offered
egen check=anymatch(`varlist'),val(-1)
drop if check
and Michael suggested
gen byte touse=1
markout touse `varlist'
(for use after the -mvdecode- command turns each -1 into missing).
Michael meant
drop if !touse
instead of
drop if touse
as the latter drops all observations with no missing values. After
-mvdecode- another -drop- command is possible:

mvdecode `varlist', mv(-1)
local commavs: subinstr loc varlist " " ",", all
drop if mi(`commavs')

Note how Kit and Michael both created an indicator variable that flags
observations with any missing values, or without any, and can then
drop if <condition met>
if necessary, but in most cases, you do not need to actually drop the
observations.  For example,
reg varlist
su varlist if e(sample)
will restrict the second command to observations with no missings in
varlist (see -help postest- for the use of e(.) constructs). The
command if <condition met>
construct is very useful, though if you are new to Stata you may find
it counterintuitive to append the -if- qualifier to every command
after you make the "anymissing" or "nomissing" indicator variable, and
may prefer to drop data.  Both approaches present risks to the sloppy
Stata user--the first offers you the option of forgetting the -if-
qualifier and getting an unwanted result, and the second the option of
dropping data that may be useful in the future.

On the differences among
drop if !touse
drop if touse
drop if touse==0
drop if touse!=1
and related commands, see e.g.
http://www.stata.com/support/faqs/data/trueorfalse.html
http://fmwww.bc.edu/RePEc/nasug2001/tvl05.txt
help m2_op_logical

Somewhat oddly, -help missing- does not describe the
drop if missing(`commavs')
construct, but -help progfun- does (scroll down to missing).  I also
think some of the true-or-false explanation should really be contained
in -help exp- and -help operators- (both of which are more terse than
they need be).

On 6/20/07, bunny , lautloscrew.com <[email protected]> wrote:
i have several non-response in my dataset that are coded -1 .
i�d like to drop any observation (row) where one or more columns
contains a -1.
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index