Stata/Problems

From Wikibooks, open books for an open world
< Stata
Jump to: navigation, search

Report your problems with Stata on this page :


Round[edit]

Sometimes the round() function does not perform its job. For instance, in this case round does not change anything to the value of the local toto.

. local toto = 9.950000000000001
. di "`toto'"
9.950000000000001
. local toto2 = round(`toto',.01)
. di "`toto2'"
9.950000000000001

The temporary solution to this problem is to treat toto as a string and to use regexm to round it :

. local toto = 9.950000000000001
. di "`toto'"
9.950000000000001
. if regexm("`toto'","([0-9].[0-9][0-9])"){
.         local toto = regexs(1)
.         di "`toto'"
9.95
.         }