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
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
I have another huge problem with my observation data: Due to 'real life' observation restrictions,
we had to code every action of the oberved person. Each action was described by a number of
variables and the start and end time/duration. So the data looks like this.

Nr
start time      end time        action-type     var 1   var2... ...varn obsDay
1 8:00:00       8:00:20        70              100     200     ....450       1
2 8:00:10       8:00:40        85              103     205     ...460        1
...
x 16:00:00  16:03:30      70        100     0       ...450        z

As you can see, some of the actions are overlapping due to 'multi tasking', so they use the same
time, at least partially; and each action has a different length.

Now I would like to reorganize the data to a time based matrix with equal steps; each case should
represent a 5 sec. step (the smallest possible length). If there are two (or y) cases taking up the
same time, the action type and var codes should be added as AT 2, var 2-1, var 2-2 to var 2-n or AT
y, var y-1, var y-2, var y-n. (The number of the multiple tasks is in no case higher than 4 - no
individual was able to do more than 4 things at once...;-) - so y<=4)

So the output data should look like this.

Nr start time      action-type     var 1   var2... ...varn    AT2        var2-1   var2-2  var2-n
1 8:00:00         70             100     200        450      0           0       0       ...0
2 8:00:05         70             100     200        450      0           0       0       ...0
3 8:00:10         70             100     200        450     85           103     205     ...460
4 8:00:15         70             100     200        450     85           103     205     ...460
5 8:00:20         85             103     205        460      0           0       0       ...0
6 8:00:25         85             103     205        460      0           0       0       ...0
7 8:00:30         85             103     205        460      0           0       0       ...0
8 8:00:30         85             103     205        460      0           0       0       ...0
...
x16:03:25       70        100     0          450      0           0       0       ...0


*(A) By Ray to SPSSX-L on 2002/07/21.

DATA LIST LIST /Nr(F8) stime etime(2TIME8) atype var1 var2 var3 var4 day(6F8.0).
BEGIN DATA.
1 8:00:00  8:00:20 70    100     200   250 450  1
2 8:00:10  8:00:40 85    103     205   230 460  1
3 8:00:15  8:00:45 90    110     200   200 400  1
4 16:00:00 	16:03:30 70  100     0     200 450  10
5 16:01:25 	16:02:05 75  100     0     200 450  10
END DATA.
LIST.

COMPUTE #s=stime. 

* Next line assumes the maximum duration of an activity is 24 hours.
* 24*60*60/5=17280.
LOOP cnt=1 TO 17280.
COMPUTE stime=#s.
XSAVE OUTFILE='c:\\temp\\data1.sav' KEEP=stime atype var1 TO var4 .
COMPUTE #s=#s + 5.
END LOOP IF stime>=etime.
EXECUTE.
GET FILE='c:\\temp\\data1.sav'.

SORT CASES BY stime atype.
COMPUTE casen=$CASENUM.

RANK VARIABLES=casen BY stime /RANK INTO idx.
VECTOR at(4F8) /var1_(4F8) /var2_(4F8) /var3_(4F8) /var4_(4F8).


COMPUTE at(idx)=atype.


DO IF idx=1. 
+	COMPUTE var1_1=var1.
+	COMPUTE var1_2=var2.
+	COMPUTE var1_3=var3.
+	COMPUTE var1_4=var4.
ELSE IF idx=2.
+	COMPUTE var2_1=var1.
+	COMPUTE var2_2=var2.
+	COMPUTE var2_3=var3.
+	COMPUTE var2_4=var4.
ELSE IF idx=3.
+	COMPUTE var3_1=var1.
+	COMPUTE var3_2=var2.
+	COMPUTE var3_3=var3.
+	COMPUTE var3_4=var4.
ELSE IF idx=4.
+	COMPUTE var4_1=var1.
+	COMPUTE var4_2=var2.
+	COMPUTE var4_3=var3.
+	COMPUTE var4_4=var4.
END IF.

AGGREGATE
  /OUTFILE=*
  /BREAK=stime
  /at1 TO at4 = FIRST(at1 TO at4) 
  /var1_1 TO var1_4  = FIRST(var1_1 TO var1_4)
  /var2_1 TO var2_4  = FIRST(var2_1 TO var2_4)
  /var3_1 TO var3_4  = FIRST(var3_1 TO var3_4)
  /var4_1 TO var4_4  = FIRST(var4_1 TO var4_4).

COMPUTE nr=$CASENUM.
ADD FILES FILE=* /KEEP=nr stime 
	at1 var1_1 TO var1_4 
	at2 var2_1 TO var2_4 
	at1 var3_1 TO var3_4 
	at1 var4_1 TO var4_4.