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

From |
David Kantor <kantor.d@att.net> |

To |
statalist@hsphsun2.harvard.edu |

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/

**Follow-Ups**:**Re: st: Drop variables satisfying a condition***From:*"Austin Nichols" <austinnichols@gmail.com>

**References**:**st: Drop variables satisfying a condition***From:*"Guillermo Villa" <guillermo@baphealth.com>

**Re: st: Drop variables satisfying a condition***From:*"David Elliott" <dcelliott@gmail.com>

- Prev by Date:
**st: RE: RE: Drop variables satisfying a condition** - Next by Date:
**st: RE: RE: Drop variables satisfying a condition** - Previous by thread:
**Re: st: Drop variables satisfying a condition** - Next by thread:
**Re: st: Drop variables satisfying a condition** - Index(es):

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