Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: if expression involving a variable in a while loop


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: if expression involving a variable in a while loop
Date   Wed, 13 Jul 2011 13:56:32 -0500

Like this?

clear
input  v1  v2   v3   v4   v5   v6   v7
.96 .04 .0 0 0 0 0
.5 .3 .1 .03 .03 .03 0.01
.4 .2 .2  .15 .03 0.015 .002
.3 .3 .37 .03 0 0 0
.9 .08 .02 0 0 0 0
end

gen sum = 0
gen var_count = 1
qui {
forv i = 1/7 {
	replace sum = sum + v`i' if sum <.95
	replace var_count = var_count + 1 if sum <.95
}
}

l

Scott
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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   |   Site index