Statalist


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

re: st: check whether a variable has any missing values


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   re: st: check whether a variable has any missing values
Date   Sat, 28 Mar 2009 16:31:10 -0400

<>	
Jacob wants to see if a variable has missing values, and wrote a program to do so. I don't think that's really necessary. Using an expanded version of his test data,

     +-------------------------------+
     | bad   good   strbad   strgood |
     |-------------------------------|
  1. |   0      0        0         0 |
  2. |   .      1                  1 |
  3. |   .      3        a         b |
  4. |   1      2        c         d |
     +-------------------------------+

. foreach v of varlist _all {
  2.         qui count if missing(`v')
  3.         di "`v'  `r(N)' "
  4. }

bad  2
good  0
strbad  1
strgood  0

The function missing() does the trick just fine if you consider what it does: return true (1) or false (0) for each observation.


Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming | http://www.stata-press.com/books/isp.html
   An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index