Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Drop variables satisfying a condition


From   "Austin Nichols" <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Drop variables satisfying a condition
Date   Fri, 6 Jul 2007 11:51:25 -0400

Guillermo Villa <guillermo@baphealth.com>:
See -help confirm- or try:

prog dropzmi
syntax [varlist]
foreach var of local varlist {
di as res "Missing/zero `var' :" _col(30) _c
cap conf numeric var `var'
if _rc==0 {
 count if `var' == 0 | mi(`var')
 if r(N) == _N {
  drop `var'
  di as err "Dropped var `var'"
  }
 }
else {
 count if `var' == "0" | mi(`var')
 if r(N) == _N {
  drop `var'
  di as err "Dropped var `var'"
  }
 }
}
end
dropzmi


On 7/6/07, Guillermo Villa <guillermo@baphealth.com> wrote:
Hi,

Thanks, but I think the loop does not work with strings, so it stops when it
finds the first string in the dataset. Do you think it is possible to write
a similar loop for any variable format? I have a huge dataset, with about
500 variables, so this will be very helpful.

Thanks again.

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