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
Oliver Jones <[email protected]>
To
[email protected]
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/