Warm greetings to all. In my data file we collect the respondent usage
about a particular product in hrs and mins. The respondent can answer
hrs or mins or both. I want a new variables for todal hrs and total
mins. Data captured in the following way.
Hrs Mins
8 .
5 .
0 30
1 1
5 7
. 15
1 0
1 .
0 5
5 5
5 .
Thanks,
Lawrence
Thanks,
Lawrence
Count HRSMIS = hrs(missing).
Count MinMIS = min(missing).
and then use and if clause to clauclate the zero value back onto the
variable
If (hrsmis = 1) hrs =0.
If (minmis = 1) min =0.
from here you can then use you favourite method to work out mins or
hours
i.e
Compute Tmins = hrs*60 + mins.
Exe.
HtH
Mike
If you are referrering to total by all respondents i would create and
dummy variable and then aggr by that
Compute dummy=1.
AGGREGATE
/OUTFILE=*
MODE=ADDVARIABLES
/BREAK=Dummy
/Hrstot = SUM(Hrs) /Minstot= SUM(mins).
this will give you total minutes and total ours, you can then combine
the two similar to how i stated earlier
Why not do all that in one step, like this:
RECODE hrs min (SYSMIS=0) (else=copy).
exe.
>
> from here you can then use you favourite method to work out mins or
> hours
>
> i.e
> Compute Tmins = hrs*60 + mins.
> Exe.
>
> HtH
>
> Mike
>
--
Bruce Weaver
bwe...@lakeheadu.ca
www.angelfire.com/wv/bwhomedir
Much better way of doing it
Mike
Compute totmin = SUM(hrs*60,mins).
LOL, Neila
what about Compute Tmins = max(hrs,0)*60 + max(mins,0)
Thanks for all of your input on my query. I used the follwing syntax
and got the total mins exactly. I calculated total hrs, but in some
cases I got different value. Why it's coming? Please look the 4-6, 9
and 10 records. The total hrs come differently. How to interpret this?
Recode hrs mins (sysmis=0) (else=copy).
Compute totmin = SUM(hrs*60,mins).
compute tothrs=totmin/60.
exe.
hrs mins totmins tothrs
---- ----- ------ ------
8 0 480.00 8.00
5 0 300.00 5.00
0 30 30.00 .50
1 1 61.00 1.02
5 7 307.00 5.12
0 15 15.00 .25
1 0 60.00 1.00
1 0 60.00 1.00
0 5 5.00 .08
5 5 305.00 5.08
5 0 300.00 5.00
1) dividing an integer hours field by 60 will give the results as
hours and decimal fractions of hours
2) Neila's sum(hrs*60,mins) as the complete solution is much better
than my max(hrs,0)+max(mins,0) as a partial solution that still needs
summing.
I had mistakenly understood/misread that the SUM function required all
numerics in the fields from the Help description, but was obviously
wrong as nulls/non numerics are obviously just ignored.
Robert
It is stored as a **double** , not integer!!!
The issue is the default format (F8.2).
See FORMAT commaand eg FORMAT var (10.6 will give you 6 decimal places
> 2) Neila's sum(hrs*60,mins) as the complete solution is much better
> than my max(hrs,0)+max(mins,0) as a partial solution that still needs
> summing.
>
> I had mistakenly understood/misread that the SUM function required all
> numerics in the fields from the Help description, but was obviously
> wrong as nulls/non numerics are obviously just ignored.
Sorta ;-)
>
> Robert
hrs mins totmins tothrs
5 7 307.00 5.12
this tothrs should be 5.07.
Thanks,
Lawrence.
> hrs mins totmins tothrs
> 5 7 307.00 5.12
>
>
> this tothrs should be 5.07.
Lawrence,
Divide 7 by 60 and think again.
Brendan
--
Brendan Halpin, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F2-025 x 3147
mailto:brendan...@ul.ie http://www.ul.ie/sociology/brendan.halpin.html
You are absolutely right! Now I got my point. Thanks lot.
Thanks,
Lawrence.
> Robert Jones wrote:
> > message snipped
> >
> > 1) dividing an integer hours field by 60 will give the results as
> > hours and decimal fractions of hours
> >
>
> It is stored as a **double** , not integer!!!
> The issue is the default format (F8.2).
> See FORMAT commaand eg FORMAT var (10.6 will give you 6 decimal places
> > 2) Neila's sum(hrs*60,mins) as the complete solution is much better
> > than my max(hrs,0)+max(mins,0) as a partial solution that still needs
> > summing.
Yes thanks, I think I am digging a hole for myself, I meant what you
said.
Robert