Disaggregate Data

Introduction

Sometimes, one may start a project with aggregated data, weighted by a frequency variable. In some cases, though, disaggregating such data (creating n rows for a row with frequency n) may be desired.

SPSS Syntax Example

*1. Create test data.

data list free/gender employed frequency.
begin data
0 0 5 1 0 2 0 1 8 1 1 5
end data.value labels gender 0 ‘Female’ 1 ‘Male’ / employed 0 ‘Unemployed’ 1 ‘Employed’.*2. Write disaggregated data file.

loop # = 1 to frequency.
xsave outfile = ‘d:/temp/disaggregated.sav’ / drop frequency.
end loop.

*3. Open disaggregated data file.

get file = ‘d:/temp/disaggregated.sav’.

Notes

  • This syntax will only work if the frequency variable contains only integers. Consider the RND function for rounding frequencies if necessary.
  • The basic trick here is that XSAVE is – technically speaking – a transformation. This is why it can be used within LOOP.

Post Author: Zahid Farid