Date: Fri, 5 Nov 2004 14:01:47 -0500
Reply-To: Richard Ristow <firstname.lastname@example.org>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: Richard Ristow <email@example.com>
Subject: Re: selecting cases by date range
In-Reply-To: <3A9E375AF395774E8BF7211238D97A401B30F4@fsmail.SHEEOPRIV.lo cal>
Content-Type: text/plain; charset="us-ascii"; format=flowed
At 12:48 PM 11/5/2004, Tara Bisel wrote:
>I have a data set that lists 4 years (2000, 2001, 2002, 2003) of data
>by state. I have a second data set containing the same state data for
>the year 2004. I need to merge into the second data set, the data for
>the first 4 years but ONLY if the state has data for the entire series
>(i.e. for years 2000-2004). When I do a merge (add cases), all 50
>states come in. I wish add cases had the same option as add variables
>to match on a certain variable. Can anyone offer a solution? Thanks
A 'match' variable for ADD FILES would be a large change to how SPSS
works. SPSS is mainly a case-at-a-time processor; what you'd want to do
is test on a group of cases at once.
But there are ways to do that. Generally, you mark which states you
want in a second file, and then MATCH FILES that file back in. Below is
untested code. It assumes that you have done the ADD FILES; and the
results, with all 50 states, is in c:\MySPSS\AllStates.SAV; and that
file is in order by the state ID variable, which I will call STATE.
IF <case is for year2000> GOT2000=1.
IF <case is for year2001> GOT2001=1.
IF <case is for year2002> GOT2002=1.
IF <case is for year2003> GOT2003=1.
IF <case is for year2004> GOT2004=1.
/ GOT2000 GOT2001 GOT2002 GOT2003 GOT2004
=MAX(GOT2000 GOT2001 GOT2002 GOT2003 GOT2004).
RECODE GOT2000 GOT2001 GOT2002 GOT2003 GOT2004
=MIN(GOT2000 GOT2001 GOT2002 GOT2003 GOT2004).
/* Now, GOT_ALL is 1 for states with data for */
/* all five years. */
/* Select the states you want, save as desired*/
SELECT IF (GOT_ALL = 1).