Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Mark observations with missing data


From   Richard Herron <[email protected]>
To   [email protected]
Subject   st: Mark observations with missing data
Date   Fri, 6 Jan 2012 13:00:45 -0500

I learned about -dropmiss- (Stata Journal) from this Stata List post:
http://www.stata.com/statalist/archive/2010-05/msg00513.html

But I would like to keep all observations and just mark the ones with
missing observations in a given -varlist-. This way with an -if-
statement I can find summary statistics for the same data that I will
later use in regressions. I provide a hackish solution below, but is
there a better way? Is there anything flawed with my approach? I am a
little wary of loops and my own coding. Thanks!

Here is my hackish solution if I want to mark observations with any
missing variables.

* begin code
sysuse auto, clear
replace price = . in 1
replace mpg = . in 2
list in 1/5

* hackish solution
generate byte complete = 1
foreach x of varlist * {
    replace complete = 0 if missing(`x')
}
list in 1/5
* end code
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index