Hi Statalist,
The following issue can be worked around but I'd like to know how this happens regardless because of how odd it is.
So, in the process of setting up some nested for-loops that iterate through various values within a grid-search, I noticed that specific values for a loop do not return what they should (or at least what I expected):
returns 0.05 and 0.1
For every other forvalues-loop I had been using thus far the max value of the interval is also returned. See this super simple example:
returns 1, 2, and 3 as you'd expect
Now, I tried to check if there was an issue with the specific values in 0.05(0.05)0.15 so I extended the interval to 0.2 and 0.25 but then the loop returns the values including the max value of the interval just like I'd expect it to:
returns 0.05, 0.1, 0.15, 0.2, and 0.25
For the loop that was supposed to iterate though the values 0.05, 0.1, and 0.15 I instead used this:
It works, but I feel like I shouldn't have to do this. I'm new to Stata (thus far I mostly used python and SQL) so I wonder if this is somehow intended or a bug, because I have absolutely no clue why the first loop I posted doesn't work as intended.
Using Stata 15.1 (up to date)
The following issue can be worked around but I'd like to know how this happens regardless because of how odd it is.
So, in the process of setting up some nested for-loops that iterate through various values within a grid-search, I noticed that specific values for a loop do not return what they should (or at least what I expected):
Code:
forvalues i = 0.05(0.05)0.15 { di `i' }
For every other forvalues-loop I had been using thus far the max value of the interval is also returned. See this super simple example:
Code:
forvalues i = 1(1)3 { di `i' }
Now, I tried to check if there was an issue with the specific values in 0.05(0.05)0.15 so I extended the interval to 0.2 and 0.25 but then the loop returns the values including the max value of the interval just like I'd expect it to:
Code:
forvalues i = 0.05(0.05)0.25 { di `i' }
For the loop that was supposed to iterate though the values 0.05, 0.1, and 0.15 I instead used this:
Code:
foreach i in 0.05 0.1 0.15 { di `i' }
Using Stata 15.1 (up to date)
Comment