I have to use SPSS to conduct an analysis at work and am not yet familiar with the LOOP command syntax in SPSS. Was wondering if anyone could help me translate the following Stata code into SPSS syntax.

The basic background of the problem is this - we have a data set containing arrest data over time (wide form) by sequential dates but want these following arrests to be moved down to the following row if they are greater than new "index" arrest dates and the person id (non-unique - repeats) is the same (for instance, the date for the fourth arrest is greater than the next index arrest for the same person - we want the fourth, and all following arrests, to then be associated with both the first index arrest and the next index arrest on the row below it). The following Stata code does just that, but now I need to conduct the very same process in SPSS and am a lot less familiar with SPSS syntax (particularly, the LOOP command). Any and all help would be greatly appreciated!

sort person_id index_arr

by person_id: gen index_id=_n

sort person_id index_id

forvalues X=1/10 {

by person_id: egen temp`X'=max(arr`X')

drop arr`X'

rename temp`X' arr`X'

}

forvalues X=1/10 {

replace arr`X'=. if index_arr>=arr`X'

}

reshape long arr, i(case_id) j(num)

gen one=1 if arr~=.

sort case_id num

by case_id: egen sumone=sum(one)

drop if arr==. & sumone>0

drop if arr==. & sumone==0 & num>1

sort case_id num

by case_id: gen newnum=_n

drop num one sumone

reshape wide arr, i(case_id) j(newnum)