Question

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.

Was it helpful?

Solution

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top