Selecting cases from a merged dataset

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

Steinberg
Posts: 8
Joined: Mon Jul 20, 2015 12:44 pm

Selecting cases from a merged dataset

Postby Steinberg » Mon Jul 20, 2015 1:37 pm

Hello dear fellow SPSS programmers.

I just got in to SPSS after years of programming in SAS and other programs due to a new job.

I have a problem, which I'm looking for some help to solve. I have combined two datasets (sampled in 2011 and 2014), where some of the cases are in both datasets and some are not. The cases are identified by a specific id applied to each individual in both years; so for example if there are two cases with the id of “7” in the combined dataset (I’ve sortet the dataset by id), I know it's the same person, who has answered both in 2011 and 2014.

Now; my mission is to select only the cases, which have answered the survey in both 2011 and 2014 using the id-variable.
Initially, my idea was to use the lag operator:
SELECT IF id=lag(id).
EXECUTE.
Of course that only works one way. So I thought there might be a “reverse lag operator”. In SAS I’ve worked with “look ahead method”, which works pretty well. Is there any similar method in SPSS or have you any experience with this type of data manipulation?

Ps. I posted my question here, because I need a syntax.
JonPedersen
Posts: 119
Joined: Wed May 25, 2011 7:07 am
Contact:

Re: Selecting cases from a merged dataset

Postby JonPedersen » Mon Jul 20, 2015 8:57 pm

Hi,
No, there is not, irritatingly, a function that looks forward. A possibility is to compute a variable that indicates if lag(id)=id, and then sort the file, by ID and the indicator variable, and do the lag again, then select.
But you do have the shift cases command, that can be used for more or less the same thing, but since shift cases cannot be combined with a condition, and reads the dataset, one might as well use the lag and sort.
hth,
Jon
RubenGeert
Posts: 100
Joined: Mon May 19, 2014 6:06 am

Re: Selecting cases from a merged dataset

Postby RubenGeert » Tue Jul 21, 2015 4:34 am

SPSS' CREATE command "looks forward". However, I personally prefer reversing the order of the cases and then use LAG. If you're not sure how LAG works, see http://www.spss-tutorials.com/spss-lag-function/.
Steinberg
Posts: 8
Joined: Mon Jul 20, 2015 12:44 pm

Re: Selecting cases from a merged dataset

Postby Steinberg » Wed Jul 22, 2015 7:37 am

Thanks a lot. I really appreciate your help.

Sorry for my response delay.

I’ve come up with the same strategy as well. First, I sort the merged dataset in ascending order and then select cases that satisfy the id=lag(id).
After I sort the merged dataset in descending sequence and make use of the same operation.
Finally, I can merge the two datasets.

Thanks again for you support on my rather vague question.

Who is online

Users browsing this forum: No registered users and 2 guests

cron