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
Phil Clayton <[email protected]>
To
[email protected]
Subject
Re: st: forvalues loop doesn't work?
Date
Mon, 7 May 2012 20:11:34 +1000
Or more neatly:
egen q_cutoff90=pctile(quantity), p(90) by(index)
Qian, I think you might have confused the -if- command (used in programming) with the -if- qualifier (used to select subsets of your data). For most tasks you would want to use the -if- qualifier, whereas you were using the command. See -help if-
Phil
On 07/05/2012, at 7:52 PM, Ronnie Babigumira wrote:
> 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/
*
* 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/