Translating Stata Code into SPSS Syntax

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

sed89
Posts: 1
Joined: Fri Feb 08, 2013 12:42 pm

Translating Stata Code into SPSS Syntax

Postby sed89 » Fri Feb 08, 2013 12:53 pm

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)
mirirai
Posts: 6
Joined: Thu Feb 07, 2013 9:46 am

Re: Translating Stata Code into SPSS Syntax

Postby mirirai » Mon Feb 25, 2013 2:02 pm

I'm Sorry, from your description I don't get what you want to do. Maybe an example with before and after table would help.

Do I see this right, that you have the variables "arr" and "arr1" to "arr10" in your data-set?

Who is online

Users browsing this forum: No registered users and 2 guests

cron