Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: looping to value of a variable

From   Richard Fox <>
To   "" <>
Subject   st: looping to value of a variable
Date   Wed, 22 Feb 2012 15:09:51 +0000

Dear all,

I want to loop to the value of a variable. Let's say I have generated the number of non-missing values in a row of data (maxFU in example below). I want to loop to that value which clearly can differ between records.

The following does the job but feels like cheating.

egen maxFU = rownonmissing(FU1 FU2 FU3 FU4 FU5 )

local N=r(N)
forvalues i = 1/`N' {
					local sp = maxFU[`i']
					forvalues j=1/`sp'	{
								qui replace flag`j'=1 if DFU`j'==.

There must be a simpler way; any ideas? 

Best Regards

Richard Fox

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index