droping variables that have "0" for values

Re: droping variables that have "0" for values

by Kristen -
Number of replies: 0

You can write a simple function to delete all variables that sum to 0. Here is an example I wrote using nhanes data set (.do file is attached):


webuse nhanes2, clear

gen test=0

ds

local varlist `r(varlist)'

display "`varlist'"


 foreach var of local varlist {

        sum `var',  meanonly

        if r(mean)==0 {

                drop `var'

         }

 }