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

Re: st: Drop variables satisfying a condition

From   "David Elliott" <>
Subject   Re: st: Drop variables satisfying a condition
Date   Fri, 6 Jul 2007 15:26:57 -0300

Good catch, David and Austin, using summarize would fail in an
instance where one had balanced +ve and -ve nonzero values.

In the interest of parsimony, one use a cond() instead of the
if...else to handle string/numeric identification which gives:

// Remove empty variables from dataset
foreach var of varlist * {
	capture confirm string variable `var'
	quietly count if  `var' == ///
	`=cond(!_rc,`""""',"0")'| mi(`var')
	if r(N) == c(N) {
		drop `var'
		noisily display as txt "Dropping " as result "`var'"
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index