[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Drop variables satisfying a condition
From
David Kantor <[email protected]>
To
[email protected]
Subject
Re: st: Drop variables satisfying a condition
Date
Fri, 06 Jul 2007 12:17:09 -0400
David Elliot wrote in response to the question from Guillermo Villa:
[...]
[...] quietly summarize `var'
if `r(sum)' == 0 { // r(sum) is returned by summarize
drop `var'
display as txt "Dropping " as result "`var'"
}
I don't think that testing `r(sum)' == 0 is appropriate. This
indicates that the sum of the values is 0. I think you really want to
test whether all the values are 0. And it's easy to construct an
example where the sum is 0 but not all values are 0.
I would suggest...
capture confirm `var' == 0
if ~_rc {
drop `var'
}
Another thing you may want to test is whether r(sd) ==0 after a
-summarize-, which tells you that the values are constant.
Also note that the quotes around r(sum) were unnecessary, though that
is a moot point.
HTH
--David
*
* 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–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |