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
[email protected]
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/