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

RE: st: Re: Dropping variables conditionally


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Re: Dropping variables conditionally
Date   Thu, 14 Apr 2005 12:07:29 +0100

However, note that -dropmiss- embedded in 
code will be slower than your code. In 
essence, you rediscovered the very simple 
logic of -dropmiss-: 

for each variable 
	if there's nothing of interest -drop- it 

That said, if your loop finds nothing, your 
macro droplist evaluates to "drop ", which is 
not what you want. 

Nick 
n.j.cox@durham.ac.uk 

Ian Watson
 
> Thanks very much. Exactly what I was looking for.

Friedrich Huebler 

> You can use -dropmiss-.

Ian Watson 

> >>   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'

*
*   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