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: if expression involving a variable in a while loop


From   Daifeng He <[email protected]>
To   [email protected]
Subject   Re: st: if expression involving a variable in a while loop
Date   Wed, 13 Jul 2011 15:45:50 -0400

Thanks, Oliver.  The codes work now.  Appreciate the help!

Best,
Daifeng

On Wed, Jul 13, 2011 at 3:25 PM, Oliver Jones
<[email protected]> wrote:
> Sorry my fault.
> Of course one has to reset the local sum back to 0 once it has reached the
> 0.95 for
> the specific row we are looking at currently.
>
>
> Am 13.07.2011 21:22, schrieb Daifeng He:
>>
>> Thanks, Scott.  The code works and it's exactly what I had wanted.
>>
>> Oliver, your codes look reasonable to me too but when I run them, only
>> the first obs is filled in with values for the two newly-generated
>> variables.  I will try to figure it out.
>>
>> Joerg, yes, my weight variables are sorted for each obs, but your
>> codes are illuminating and I learned from them too.
>>
>> Guys, thanks for all your help!
>>
>> Kind regards,
>> Daifeng
>>
>>
>>
>> On Wed, Jul 13, 2011 at 2:56 PM, Scott Merryman
>> <[email protected]>  wrote:
>>>
>>> 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/
>>>
>>
>> *
>> *   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/
>
> --
> Universität Bielefeld
> Fakultät für Wirtschaftswissenschaften
> Lehrstuhl für Ökonometrie und Statistik
> - -
> Bielefeld University
> Faculty of Business Administration and Economics
> Chair of Econometrics and Statistics
> - -
> Raum / room:  V9-110
> Tel / phone:  +49 (0)521 106 4871
> ---
> *
> *   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