Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: -forvalues- and decimal numbers in the numlist


From   [email protected]
To   [email protected]
Subject   st: -forvalues- and decimal numbers in the numlist
Date   Sat, 11 Sep 2004 20:36:28 +0200

Dear all,

I am writing a program with a -forvalues- loop in it. I encountered a strange problem (Stata 8.2) which can be illustrated by this sample code:

forvalues z = 15(1)30 {
di "current maximum is: `z'"
forvalues i = 0(0.1)`=`z'' {
local a = round(`i',0.01)
}
di "a is: `a'"
}

Output is

current maximum is: 15
a is: 15
current maximum is: 16
a is: 16
current maximum is: 17
a is: 17
current maximum is: 18
a is: 18
current maximum is: 19
a is: 19
current maximum is: 20
a is: 19.9
current maximum is: 21
a is: 20.9
current maximum is: 22
a is: 21.9
current maximum is: 23
a is: 22.9
current maximum is: 24
a is: 23.9
current maximum is: 25
a is: 24.9
current maximum is: 26
a is: 25.9
current maximum is: 27
a is: 26.9
current maximum is: 28
a is: 27.9
current maximum is: 29
a is: 28.9
current maximum is: 30
a is: 29.9

Stata stops looping at the second last value in the numlist from 20 onward. This behaviour continues until 76, from where on the correct value is returned again. This seems to happen only with decimal numbers, and only with some of them (compare to -forvalues i = 0(0.125)`=`z'' -). I can't really see a pattern. Maybe someone can give me a clue and tell me what to do about it.

Thanks a lot and best wishes,
Eva Poen




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index