[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
eva.poen@unisg.ch |

To |
statalist@hsphsun2.harvard.edu |

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

- Prev by Date:
**RE: st: RE: estout and Nagelkerke R2** - Next by Date:
**st: RE: -forvalues- and decimal numbers in the numlist** - Previous by thread:
**st: RE: Tabulate and date format display** - Next by thread:
**st: RE: -forvalues- and decimal numbers in the numlist** - Index(es):

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