Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Sergiy Radyakin <serjradyakin@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Drop observations with multiple zero values |
Date | Fri, 7 Jun 2013 16:59:51 -0400 |
Type in Stata (not in browser): net from http://www.adeptanalytics.org/radyakin/stata/dropifallz/ Sergiy On Fri, Jun 7, 2013 at 4:53 PM, Jeph Herrin <stata@spandrel.net> wrote: > > egen diff=diff(vars_*) > egen max=rowmax(vars_*) > drop if max==0 & diff==0 > > > > On 6/7/2013 4:32 PM, G. Anderson wrote: >> >> Sorry- didn't see this. Thank you. >> >> Is there any way to standardise the process so I can use a varlist and do >> not have to manually count the number of >> variables in that list? >> >> >> >> >> On Jun 7 2013, Sergiy Radyakin wrote: >> >>> for negatives you can use >>> tempvar r >>> egen `r'=anycount(A B C),values(0) >>> drop if `r'==3 >>> >>> where 3 is the number of variables in your varlist specified in the >>> anycount function. >>> Sergiy >>> >>> On Fri, Jun 7, 2013 at 4:06 PM, Sergiy Radyakin <serjradyakin@gmail.com> >>> wrote: >>>> >>>> tempvar r >>>> egen `r'=rowtotal(A B C) >>>> drop if `r'==0 >>>> >>>> missings are treated as zeroes and things get more complicated if any >>>> of the vars may contain negatives. >>>> Best, Sergiy >>>> >>>> On Fri, Jun 7, 2013 at 4:02 PM, G. Anderson <ga274@cam.ac.uk> wrote: >>>>> >>>>> Hi, >>>>> >>>>> Does anybody know how I can drop observations if a number of values are >>>>> zero? >>>>> >>>>> I can do this by manually inputting drop if( A==0 & B==0 & C==0) But I >>>>> was wondering if there was any easier way of >>>>> doing this (especially when I have a lot of variables)- perhaps using >>>>> varlist somehow? >>>>> >>>>> >>>>> Many Thanks, >>>>> >>>>> Gareth * >>>>> * For searches and help try: >>>>> * http://www.stata.com/help.cgi?search >>>>> * http://www.stata.com/support/faqs/resources/statalist-faq/ >>>>> * http://www.ats.ucla.edu/stat/stata/ >>> >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/faqs/resources/statalist-faq/ >>> * http://www.ats.ucla.edu/stat/stata/ >>> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/faqs/resources/statalist-faq/ >> * http://www.ats.ucla.edu/stat/stata/ >> >> > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/statalist-faq/ > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/