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 on April 23, 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   Oliver Jones <ojones@wiwi.uni-bielefeld.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: if expression involving a variable in a while loop
Date   Wed, 13 Jul 2011 20:38:36 +0200

Since you want to look at every row/observation separately you might have to use
a for loop? Maybe something like

gen sum = 0
gen n_95 = .

count
local maxrow = `r(N)'
for row = 1/`maxrow' {
   local i=1
   while sum <= 0.95 {
      replace sum = sum + var`i' in `row'
      local sum = sum[`row']
      local `i' = `i' + 1
      replace n_95 = `i' in `row'
   }
}


Best
Oliver



Am 13.07.2011 20:00, schrieb Daifeng He:
Here are my codes:

gen sum=0
gen n_95=.
local i=1

while sum<=0.95 {

       replace sum=sum+var`i'

       local `i'=`i'+1

       replace n_95=`i'

}

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


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