program define fodstr /* newvar oldvar */
        version 5.0
        local newvar "`1'"
        local oldvar "`2'"

        tempvar wrk hrs mins secs
        quietly {
                gen double `wrk' = round((`oldvar' - int(`oldvar'))*24, /*
                                */ 1/(60*60*24))
                gen `hrs' = int(`wrk')
                replace `wrk' = round((`wrk' - `hrs')*60,1/(60*60))
                gen `mins' = int(`wrk')
                replace `wrk' = (`wrk' - `mins')*60
                gen `secs' = round(`wrk',1)

                twodig `newvar' `hrs'

                drop `wrk'
                twodig `wrk' `mins'
                replace `newvar' = `newvar' + ":" + `wrk'

                drop `wrk'
                twodig `wrk' `secs'
                replace `newvar' = `newvar' + ":" + `wrk'

                replace `newvar' = "" if `hrs'==.
        }
end

program define twodig /* newvar oldvar */
        local newvar "`1'"
        local oldvar "`2'"

        capture drop `newvar'
        qui gen str2 `newvar' = "0" + string(`oldvar') if `oldvar'<10
        qui replace `newvar' = string(`oldvar') if `oldvar'>=10
end
exit