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]

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/

**Follow-Ups**:**Re: st: if expression involving a variable in a while loop***From:*Scott Merryman <scott.merryman@gmail.com>

**References**:**st: if expression involving a variable in a while loop***From:*Daifeng He <dhe.statlist@gmail.com>

- Prev by Date:
**Re: st: Identify combinations without respect to the order of the elements** - Next by Date:
**st: count differents values of a variable** - Previous by thread:
**st: if expression involving a variable in a while loop** - Next by thread:
**Re: st: if expression involving a variable in a while loop** - Index(es):