You could try the following code. In this code, I have assigned 100 turtles with wealth between 0 and 99. The code will count the number of consecutive ticks for which the wealth of a turtle remains above 50. If the total count of ticks equals or exceeds 200, then the turtle variable 'counter' is set to 1.
At the end of the run, you can count the number of turtles with 'counter' = 1.
turtles-own [counter wealth time-counter]
to setup
ca
reset-ticks
create-turtles 100
[
set counter -1
set wealth random 100
]
end
to go
;check if wealth is equal to or greater than 50. If yes set time-counter time-counter + 1
; If wealth is less than 50, set time-counter = 0
ask turtles
[
ifelse wealth >= 50 and counter = -1
[
set time-counter time-counter + 1
]
[
set time-counter 0
]
;if time-counter >= 200, set counter to 1
if time-counter >= 200
[
set counter 1
]
]
tick
end
Hope this helps.