Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Dropping variables conditionally


From   Ian Watson <i.watson@econ.usyd.edu.au>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   st: Dropping variables conditionally
Date   Thu, 14 Apr 2005 12:27:04 +1000

  My particular task is to eliminate all variables from the dataset
  which are empty, that is, have no observations. The following bit of
  code has done this, but surely there is a simpler way which I have
  overlooked?

local droplist "drop "
foreach v of varlist * {
    qui count if !mi(`v')
    if r(N) == 0 local droplist "`droplist' `v'" 
}
`droplist'


-- 
Kind regards, 
Ian

-------------------------------
Ian Watson
Senior Researcher
acirrt, University of Sydney
NSW, 2006, Australia

phone: 02 9351 5622
email:i.watson@econ.usyd.edu.au
www.acirrt.com
-------------------------------

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