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

Re: st: Drop variables satisfying a condition

From   "Austin Nichols" <>
Subject   Re: st: Drop variables satisfying a condition
Date   Fri, 6 Jul 2007 13:03:19 -0400

David Kantor et al.:
I agree that testing sum=0 is inappropriate, and there is no need to
invoke -summarize- and all its machinery when -count- will do; but I
think David Kantor does not mean
capture confirm `var' == 0
but rather
capture assert `var' == 0
as the first will always fail.

Given that Maarten and I have both posted programs to handle the
string variables, David Elliot's program need not be fixed, I think.

On 7/6/07, David Kantor <> wrote:
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.


*   For searches and help try:

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