Insert missing cases (within id)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | ** Job is to ensure that all id have the 4 quarters present. ** rlevesque@videotron.ca. data list free / id quarter wages. begin data 1 1 6000 1 3 6100 2 1 7000 2 2 7200 2 4 7150 end data . *Your data file must be sorted. SORT CASES BY id quarter. SAVE OUTFILE='c:\\temp\\data temp.sav'. AGGREGATE /OUTFILE=* /BREAK=id /quarter = N(quarter). * Create a file with each id and all 4 quarters. LOOP qtr=1 TO 4. + XSAVE OUTFILE='temp.sav' /KEEP=id qtr. END LOOP. EXECUTE. GET FILE='temp.sav'. RENAME VARIABLE (qtr=quarter). * Matching the 2 files fills in the gaps. MATCH FILES /FILE=* /FILE='C:\\temp\\data temp.sav' /BY id quarter. EXECUTE. |
Related pages
...