Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Re: dummy based on the outcome of many variables


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: dummy based on the outcome of many variables
Date   Thu, 26 Feb 2004 14:35:57 -0000

gen dummy = 0 
foreach v of var a b c d e f { 
	replace dummy = dummy + (`v' != 0) 
} 
replace dummy = dummy >= 5 

Alternatively, with -egenmore- installed 

egen dummy = rcount(a b c d e f), cond(@ != 0) 
replace dummy = dummy >= 5 

Nick 
n.j.cox@durham.ac.uk 

R.E. De Hoyos
 
> how can I create a dummy=1 when at least 5 out of 6 variables 
> are different from zero?

*
*   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/



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