# st: AW: Transforming a decimal number into hours and minutes

 From "Martin Weiss" To Subject st: AW: Transforming a decimal number into hours and minutes Date Fri, 7 Aug 2009 14:50:31 +0200

```<>

*************
clear*

inp hours
3.89
2.43
6.53
9.09
1.43
end

gen double fullhour=int(hours)
gen double fraction=hours-fullhour

gen minutes=round(fraction*60,1)

list fullhour minutes, /*
*/ noobs
*************

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Peer Skov
Gesendet: Freitag, 7. August 2009 12:54
An: statalist@hsphsun2.harvard.edu
Betreff: st: Transforming a decimal number into hours and minutes

Hi listers,
I am working with a survey dataset. The individuals have all been asked to
report how much time they have spent on a specific activity. The answers are
recorded in the dataset as a numeric variable the provided answers are
integers (hours worked).
I want to assign conditional means to the individuals who have not answered
the hour question. Calculating the means leads to a decimal number and
therefore I need to transform the decimal-part into minutes. Since Statas
date function only work with strings and a decimal number cannot be turned
in to a string I am not sure how I can solve it.

Code:
bysort edu: egen hoursA=mean(hours)
replace hours=hoursA if hours ==. & active == 1

Example.
I need to turn 3.89 into 3.53

All thoughts are much appreciated.
Best,
Peer.
_________________________________________________________________
Drag n? drop?Get easy photo sharing with Windows Live? Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```