Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: forvalues loop doesn't work?


From   Ronnie Babigumira <[email protected]>
To   [email protected]
Subject   Re: st: forvalues loop doesn't work?
Date   Mon, 7 May 2012 11:52:13 +0200

Looks like the problem is that the -replace- is not conditional so that last r(p90) replaces all

Does this do what you want?

qui sum index
forvalues i=1/`r(max)'{
sum quantity if index == `i', detail
replace q_cutoff90=r(p90) if index == `i'
}



-- 
010100100110111101101110011011100110100101100101




On Monday, May 7, 2012 at 11:42 AM, econqian222 wrote:

> Hi, statalist
> I have tried to record percentile 90 of quantity for each value of
> index, unfortunately, my result still only record the percentile 90 of
> quantity for all the values of index, so what's the problem of my program?
> My program goes like the following:
> 
> forvalues i=1/4760{
> if index==`i' {
> sum quantity, detail
> replace q_cutoff90=r(p90)
> }
> }
> 
> My data goes as this:
> index quantity q_cutoff90
> 1 4 .
> 1 67 .
> 2 89 .
> 2 57 .
> 2 91 .
> 3 98 .
> 3 95 .
> 3 27 .
> . . .
> . . .
> 4760 88 .
> 4760 56 .
> 
> Many thanks
> Qian
> 
> --
> View this message in context: http://statalist.1588530.n2.nabble.com/forvalues-loop-doesn-t-work-tp7534631.html
> Sent from the Statalist mailing list archive at Nabble.com (http://Nabble.com).
> *
> * 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/



*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index