Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mean of a percentage of 2 rows in spss

Tags:

spss

I have data of the following kind

pers.id       holiday
1                  0
1                  1
1                  0
1                  0
1                  1
1                  0
2                  0
2                  0
2                  1
2                  0
5                  0
5                  1
5                  0
9                  0
9                  0
9                  0
9                  0

I now want to compute the mean of the percentage of holidays/workdays. In this case we have 4 persons. The number of rows for each person.id is the number of days he has been working. So if pers.id has 6 rows he has been working 6 days. Holiday can either be 0 or 1 whether that person had a holiday on that day or not. I now want to compute the mean of holidays/workdays for all person.id

In the above example that would be:

( 2/6 + 1/4 + 1/5 + 0/4) / 4

How can I do this in SPSS Syntax ? I also need a Confidence Interval for that value.

like image 611
spore234 Avatar asked Jan 01 '26 20:01

spore234


1 Answers

Below is an example of using AGGREGATE to generate the requested table of proportions. There are so many different confidence intervals for proportions (see this NABBLE discussion that also links to various code snippets) so I'll let you figure out which confidence interval you want on your own.

data list free / pers.id holiday.
begin data
1                  0
1                  1
1                  0
1                  0
1                  1
1                  0
2                  0
2                  0
2                  1
2                  0
5                  0
5                  1
5                  0
9                  0
9                  0
9                  0
9                  0
end data.

DATASET DECLARE AggProp.
AGGREGATE
  /OUTFILE = 'AggProp'
  /BREAK = pers.id
  /HolidayT=SUM(holiday)
  /HolidayP=MEAN(holiday)
  /NId=N.
like image 50
Andy W Avatar answered Jan 06 '26 16:01

Andy W



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!