跳轉到內容

Stata/問題

來自華夏公益教科書,開放的書籍,開放的世界

在此頁面上報告您遇到的 Stata 問題 


有時 round() 函式無法執行其工作。例如,在本例中,round 不會更改區域性變數 toto 的值。

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

此問題的臨時解決方案是將 toto 視為字串,並使用 regexm 對其進行舍入 

. 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
.         }
華夏公益教科書