Question

I have data from an experiment that is sampling responses between 59 to 60 hz. There is no way to predict the drop-down in sampling rate throughout the experiment which runs for 18 minutes.

Each of the sampled responses are numbered from 1 to N (for total number of rows) showing relative passage of time, stored in variable 'frame'. I also have a unix time stamp marking absolute time stored in 'unixtime'. But unixtime is reported in whole integers & not in fractional units. For example:

  • 1376925380 may be repeated 59 times;
  • 1376925381 may be repeated 60 times in the data file.

I would like to create a new variable that tracks each consecutive frame (or sampled response) from 1 to 60 or from 1 to 59, as the case may be, for each given unixtime stamp in SPSS. See the desired re-arrangement below. Any help w/ appropriate SPSS-syntax is appreciated!

unixtime    newframe
1376925380  1
1376925380  2
1376925380  3
1376925380  4
1376925380  5   
1376925380  6
....
1376925380  58
1376925380  59
1376925381  1
1376925381  2
1376925381  3
1376925381  4
....        ....
1376925381  60
1376925382  1
1376925382  2
....
Was it helpful?

Solution

If I understand correctly, you can use LAG to figure out your counter between the time stamps. Example below.

*fake data.
set seed 10.
input program.
loop #i =  1 to 100.
  loop #j = 1 to TRUNC(RV.UNIFORM(59,61)).
    compute unixtime = 1376925379 + #i.
    end case.
  end loop.
end loop.
end file.
end input program.

*Using lag to calculate newframe variable.
DO IF ($casenum = 1) OR (unixtime <> lag(unixtime)).
  compute newframe = 1.
ELSE.
  compute newframe = lag(newframe) + 1.
END IF.
exe.

See related discussion for using lag at, Using sequential case processing for data management in SPSS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top