Hello
I am trying to write a loop in STATA which would sum up all even numbers of the Fibonacci sequence that are smaller or equal to 1000.
My understanding is that even numbers in this sequence are given by 4 * evennumber2 + evennumber1
So, for example, the 3rd even number in the sequence is given by 4*2+0=8
the 4th is given by 4*8+2=34 and so on and so forth
a very rough idea of what my loop would look like is
generate ef1 = 0
generate ef2 = 2
generate sum = ef1 + ef2
while ef2 <= 1000
generate ef3 = 4 * ef2 + ef1
if ef3 > 1000
exit
display ef3
else
replace ef1 = ef2
replace ef2 = ef3
I am unsure of how to write it with the correct syntax and unsure whether to use a forvalues of foreach loop. I ask for some direction.
Thank you in advance
I am trying to write a loop in STATA which would sum up all even numbers of the Fibonacci sequence that are smaller or equal to 1000.
My understanding is that even numbers in this sequence are given by 4 * evennumber2 + evennumber1
So, for example, the 3rd even number in the sequence is given by 4*2+0=8
the 4th is given by 4*8+2=34 and so on and so forth
a very rough idea of what my loop would look like is
generate ef1 = 0
generate ef2 = 2
generate sum = ef1 + ef2
while ef2 <= 1000
generate ef3 = 4 * ef2 + ef1
if ef3 > 1000
exit
display ef3
else
replace ef1 = ef2
replace ef2 = ef3
I am unsure of how to write it with the correct syntax and unsure whether to use a forvalues of foreach loop. I ask for some direction.
Thank you in advance

Comment