prog def dropempty


foreach var of varlist  *  { 	/* the wildcard "*" includes all variables */
   capture confirm string variable `var'  /* need to handle string and number differently */
   if _rc!=0 {  /* is not string */
       quietly: summarize `var'
       if `r(N)' == 0  {  /* r(N) is returned by summarize -r(N)==0 is no values in the variable */
            drop `var'
            display as txt "Dropping " as result "`var'"
           }
       }

       else {  /* if a string */
           quietly count if missing(`var')
           if `r(N)' == `c(N)' {  /* r(N) is returned by count and is compared to the count of records in the dataset */
               drop `var'
               display as txt "Dropping " as result "`var'"
               }
           }
   }

   end