Looping and merging syntax support

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Looping and merging syntax support

Manmit Shrimali-2
Dear All:

 

I am writing after considerable amount of efforts with no results. I
have slightly tricky situation. Below is the case.

 

Q1. Question read : Including the current trip how many trips you had in
last 10 years - if greater than one trip in any year count that as 1 for
that year.

Q2. For the year 2000 and onwards please provide all the places where
you stayed (there are 2 hotels- if respondent stayed in the hotel, they
select 1 else it will be 0). Respondent can select multiple hotels in
year. We ask data only for prior trip i.e. not including the current.
Repeat the cycle for maximum upto 5 times. Do not ask pre-2000 year
data.

 

Data file1, based on above e.g. looks like this.

Total_trip_old    Trip # in year 2000         Hotel_a_5
Hotel_b_5         Hotel_a_4         Hotel_b_4

10                               9                               1
0                  .                         .

 

Hotel_a_4 and hotel_b_4 is empty as we do not ask pre 2000 year data.

 

Hotel_a_5 is cycle 5th and Hotel_b_4 is cycle 4 and so on. So if someone
has mentioned 10 in total trip and 9 in year 2000 then he will answer
only for cycle one. If someone has mentioned 9 in total_trip_old and 1
in trip # then we will take data for 8, 7,6,5 and 4th trip.

 

Data file 2: We re-fielded the survey and then from same respondents
collected the data for pre-2000. However, this time we did not limit to
only five cycles but had asked all prior trips.  

 

Total_trip_new   Trip # in year 2000         Hotel_a_1         Hotel_b_1
Hotel_a_2         Hotel_b_2

 

 

Problem: I need to merge the data file 1 with data file 2.

 

How to do that? This is what I have so far:

 

Comp diff=total_trip_old-trip#.

vector hotel_old= hotel_a_5 to hotel_b_1.

vector hotel_new= hotel_a_5_new to hotel_b_1_new.

loop #A=1 to 26.

do if diff=1.

comp hotel_old (#a)= hotel_a_5_new .

end if.

end loop.

 

Eventually I need to create a data there has records of all the prior
trips of respondent.

 

Any help is greatly appreciated.

 

Manmiot
Reply | Threaded
Open this post in threaded view
|

Re: Looping and merging syntax support

Richard Ristow
At 06:38 PM 3/5/2007, Manmit Shrimali wrote:

Your question comes through hard to understand. Let me ask for some
clarifications:

You have two files for the same respondents,

To start with: How many records in each file, for each respondent? Can
it be more than one?

Then, are you trying to end up with one record per respondent, or more?

If you can, give us the EXACT list of variables in your two files.

>Problem: I need to merge the data file 1 with data file 2.
>
>How to do that? This is what I have so far:
>
>Comp diff=total_trip_old-trip#.
>vector hotel_old= hotel_a_5 to hotel_b_1.
>vector hotel_new= hotel_a_5_new to hotel_b_1_new.
>loop #A=1 to 26.
>do if diff=1.
>comp hotel_old (#a)= hotel_a_5_new .
>end if.
>end loop.

The problem is, this has nothing to do with merging the files. That may
be a MATCH FILES or an ADD FILES, depending on what your files look
like, and what you want.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and merging syntax support

Manmit Shrimali-2
In reply to this post by Manmit Shrimali-2
Clarifications:
File 1 has 150 records and file 2nd has 150 records. The data is from
hotel so there can be multiple same ID's in both the file. I don't need
to have one record for multiple ID's. I simply want to merge pre 2000
data with the post 2000 data in file 1.

Variables in file 1 (2000>). Maximum file cycles so if someone says 11
as total trips, and was on 9th trip in year 2000 then we will ask the
cycle for 10th, and 9th trip as pre-2000 we ask in file 2. For this
respondent the data will be in Q36_5.....and Q36_4.
Total_trips
Trip_no_in_year_2000
Q36_Marriott_5
q36_Hyatt_5
Q36_Four_season_5
Q36_Marriott_4
q36_Hyatt_4
Q36_Four_season_4
Q36_Marriott_3
q36_Hyatt_3
Q36_Four_season_3
Q36_Marriott_2
q36_Hyatt_2
Q36_Four_season_2
Q36_Marriott_1
q36_Hyatt_1
Q36_Four_season_1

Data file 2 - there can be maximum 19 trips: For above mentioned case,
the respondent's pre-2000 year will be in variable q36_8th till q36_1

Q36_Marriott_19
q36_Hyatt_19
Q36_Four_season_19
TO.....
Q36_Marriott_4
q36_Hyatt_4
Q36_Four_season_4
Q36_Marriott_3
q36_Hyatt_3
Q36_Four_season_3
Q36_Marriott_2
q36_Hyatt_2
Q36_Four_season_2
Q36_Marriott_1
q36_Hyatt_1
Q36_Four_season_1

Now, I want to merge the pre-2000 data of above case into file 1 so that
I have data from his 1st trip till 10th trip.

Hope I have communicated in required form.

Thanks for your input

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Richard Ristow
Sent: Tuesday, March 06, 2007 6:11 AM
To: [hidden email]
Subject: Re: Looping and merging syntax support

At 06:38 PM 3/5/2007, Manmit Shrimali wrote:

Your question comes through hard to understand. Let me ask for some
clarifications:

You have two files for the same respondents,

To start with: How many records in each file, for each respondent? Can
it be more than one?

Then, are you trying to end up with one record per respondent, or more?

If you can, give us the EXACT list of variables in your two files.

>Problem: I need to merge the data file 1 with data file 2.
>
>How to do that? This is what I have so far:
>
>Comp diff=total_trip_old-trip#.
>vector hotel_old= hotel_a_5 to hotel_b_1.
>vector hotel_new= hotel_a_5_new to hotel_b_1_new.
>loop #A=1 to 26.
>do if diff=1.
>comp hotel_old (#a)= hotel_a_5_new .
>end if.
>end loop.

The problem is, this has nothing to do with merging the files. That may
be a MATCH FILES or an ADD FILES, depending on what your files look
like, and what you want.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and merging syntax support

Richard Ristow
At 08:50 PM 3/5/2007, Manmit Shrimali wrote:

>Hope I have communicated in required form.

Not quite. You've given the list of *DATA* variables in the files, but
not the *IDENTIFYING* variables in the files.

>File 1 has 150 records and file 2nd has 150 records. The data is from
>hotel so there can be multiple same ID's in both the file.

Where an ID represents a person? So each person can occur more than
once in each file?

>I don't need to have one record for multiple ID's.

No. The question is, whether you need to reduce to a single record for
*one* ID. Or, do you want a separate record for each trip, so each
person ('ID') has as many records as they have trips, from the two
files combined?

>Q36_Marriott_5
>q36_Hyatt_5
>Q36_Four_season_5

Are these yes/no variables? That is, one will be 'yes' and the other
two 'no', depending on which of the three hotels they stayed in?

>Variables in file 1 (2000>). Maximum file cycles so if someone says 11
>as total trips, and was on 9th trip in year 2000 then we will ask the
>cycle for 10th, and 9th trip as pre-2000 we ask in file 2.

So you have 'wide' organization in both files - multiple trips per
record. And you want 'wide' organization afterward - one record per ID,
with all the person's trips in that record.

If that's right, I recommend that
a. In each file, you use VARSTOCASES to create 'long' organization -
one record per trip, with each ID having as many records as there are
associated trips
b. Use ADD FILES to merge the two 'long' files
c. Use CASESTOVARS to create a single record per ID

-Good luck,
  Richard
Reply | Threaded
Open this post in threaded view
|

Re: Looping and merging syntax support

Manmit Shrimali-2
In reply to this post by Manmit Shrimali-2
Image ID as physician who gives multiple patient record. So one
physician can give multiple records so his ID will appear multiple
times. Also, I want a separate record for each trip, so each
person ('ID') has as many records as they have trips, from the two
files combined. If they stayed in hotel it will be 1 and if not 0. If
they are not eligible to answer then sysmis.


So you have 'wide' organization in both files - multiple trips per
record. And you want 'wide' organization afterward - one record per ID,
with all the person's trips in that record. THIS IS RIGHT. Let me try
var to case.

Thanks Richard for your input.


-----Original Message-----
From: Richard Ristow [mailto:[hidden email]]
Sent: Tuesday, March 06, 2007 7:59 AM
To: Manmit Shrimali; [hidden email]
Subject: Re: Looping and merging syntax support

At 08:50 PM 3/5/2007, Manmit Shrimali wrote:

>Hope I have communicated in required form.

Not quite. You've given the list of *DATA* variables in the files, but
not the *IDENTIFYING* variables in the files.

>File 1 has 150 records and file 2nd has 150 records. The data is from
>hotel so there can be multiple same ID's in both the file.

Where an ID represents a person? So each person can occur more than
once in each file?

>I don't need to have one record for multiple ID's.

No. The question is, whether you need to reduce to a single record for
*one* ID. Or, do you want a separate record for each trip, so each
person ('ID') has as many records as they have trips, from the two
files combined?

>Q36_Marriott_5
>q36_Hyatt_5
>Q36_Four_season_5

Are these yes/no variables? That is, one will be 'yes' and the other
two 'no', depending on which of the three hotels they stayed in?

>Variables in file 1 (2000>). Maximum file cycles so if someone says 11
>as total trips, and was on 9th trip in year 2000 then we will ask the
>cycle for 10th, and 9th trip as pre-2000 we ask in file 2.

So you have 'wide' organization in both files - multiple trips per
record. And you want 'wide' organization afterward - one record per ID,
with all the person's trips in that record.

If that's right, I recommend that
a. In each file, you use VARSTOCASES to create 'long' organization -
one record per trip, with each ID having as many records as there are
associated trips
b. Use ADD FILES to merge the two 'long' files
c. Use CASESTOVARS to create a single record per ID

-Good luck,
  Richard
Reply | Threaded
Open this post in threaded view
|

Re: Looping and merging syntax support

Manmit Shrimali-2
In reply to this post by Manmit Shrimali-2
Richard and all:

Vartocase is not working efficiently. Can you please help me writing
syntax for following:
1. Create a vector that contains information of variable X1 to X22.
Variables are in order. So I believe I will write vector X=X1 to X22.
2. Create another vector that contains information of variable Y1 to Y22
so it will be vector Y=Y1 to Y22.
3. In every cell cell of X I want to inpute value of Y i.e. X1 should
have value of Y1, X2 should have value of Y2, X3 should have value of
Y3.

If you can help me writing loop for the above situation, I think I am
able to solve my problem.





-----Original Message-----
From: Richard Ristow [mailto:[hidden email]]
Sent: Tuesday, March 06, 2007 7:59 AM
To: Manmit Shrimali; [hidden email]
Subject: Re: Looping and merging syntax support

At 08:50 PM 3/5/2007, Manmit Shrimali wrote:

>Hope I have communicated in required form.

Not quite. You've given the list of *DATA* variables in the files, but
not the *IDENTIFYING* variables in the files.

>File 1 has 150 records and file 2nd has 150 records. The data is from
>hotel so there can be multiple same ID's in both the file.

Where an ID represents a person? So each person can occur more than
once in each file?

>I don't need to have one record for multiple ID's.

No. The question is, whether you need to reduce to a single record for
*one* ID. Or, do you want a separate record for each trip, so each
person ('ID') has as many records as they have trips, from the two
files combined?

>Q36_Marriott_5
>q36_Hyatt_5
>Q36_Four_season_5

Are these yes/no variables? That is, one will be 'yes' and the other
two 'no', depending on which of the three hotels they stayed in?

>Variables in file 1 (2000>). Maximum file cycles so if someone says 11
>as total trips, and was on 9th trip in year 2000 then we will ask the
>cycle for 10th, and 9th trip as pre-2000 we ask in file 2.

So you have 'wide' organization in both files - multiple trips per
record. And you want 'wide' organization afterward - one record per ID,
with all the person's trips in that record.

If that's right, I recommend that
a. In each file, you use VARSTOCASES to create 'long' organization -
one record per trip, with each ID having as many records as there are
associated trips
b. Use ADD FILES to merge the two 'long' files
c. Use CASESTOVARS to create a single record per ID

-Good luck,
  Richard
Reply | Threaded
Open this post in threaded view
|

Re: Looping and merging syntax support

Richard Ristow
At 10:24 PM 3/5/2007, Manmit Shrimali wrote:

>1. Create a vector that contains information of variable X1 to X22.
>Variables are in order. So I believe I will write vector X=X1 to X22.

Exactly.
VECTOR X=X1 TO X22.

>2. Create another vector that contains information of variable Y1 to
>Y22 so it will be vector Y=Y1 to Y22.

Again, exactly:
VECTOR Y=Y1 TO Y22.

>3. In every cell cell of X I want to inpute value of Y i.e. X1 should
>have value of Y1, X2 should have value of Y2, X3 should have value of
>Y3.

LOOP #INDEX = 1 TO 22.
.  COMPUTE X(#INDEX) = Y(#INDEX).
END LOOP.
Reply | Threaded
Open this post in threaded view
|

Re: Looping and merging syntax support

Albert-Jan Roskam
Alternatively,

do repeat #x = x1 to x22 / #y = y1 to x22.
compute #x = #y.
end repeat print.

Maybe I had too much coffee today, but wouldn't a
simple RENAME VARIABLES also do what you want?

Cheers!
Albert-Jan

--- Richard Ristow <[hidden email]> wrote:

> At 10:24 PM 3/5/2007, Manmit Shrimali wrote:
>
> >1. Create a vector that contains information of
> variable X1 to X22.
> >Variables are in order. So I believe I will write
> vector X=X1 to X22.
>
> Exactly.
> VECTOR X=X1 TO X22.
>
> >2. Create another vector that contains information
> of variable Y1 to
> >Y22 so it will be vector Y=Y1 to Y22.
>
> Again, exactly:
> VECTOR Y=Y1 TO Y22.
>
> >3. In every cell cell of X I want to inpute value
> of Y i.e. X1 should
> >have value of Y1, X2 should have value of Y2, X3
> should have value of
> >Y3.
>
> LOOP #INDEX = 1 TO 22.
> .  COMPUTE X(#INDEX) = Y(#INDEX).
> END LOOP.
>


Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



____________________________________________________________________________________
Need a quick answer? Get one in minutes from people who know.
Ask your question on www.Answers.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: Looping and merging syntax support

Manmit Shrimali-2
In reply to this post by Manmit Shrimali-2
Richard and all:

Thanks very much for syntax help. I wish you could see how many if
statements I will not write due to loop.

Thanks Richard for your input. Really appreciate it.

Also, do repeat works fine as well.

Cheers all

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Richard Ristow
Sent: Tuesday, March 06, 2007 6:11 AM
To: [hidden email]
Subject: Re: Looping and merging syntax support

At 06:38 PM 3/5/2007, Manmit Shrimali wrote:

Your question comes through hard to understand. Let me ask for some
clarifications:

You have two files for the same respondents,

To start with: How many records in each file, for each respondent? Can
it be more than one?

Then, are you trying to end up with one record per respondent, or more?

If you can, give us the EXACT list of variables in your two files.

>Problem: I need to merge the data file 1 with data file 2.
>
>How to do that? This is what I have so far:
>
>Comp diff=total_trip_old-trip#.
>vector hotel_old= hotel_a_5 to hotel_b_1.
>vector hotel_new= hotel_a_5_new to hotel_b_1_new.
>loop #A=1 to 26.
>do if diff=1.
>comp hotel_old (#a)= hotel_a_5_new .
>end if.
>end loop.

The problem is, this has nothing to do with merging the files. That may
be a MATCH FILES or an ADD FILES, depending on what your files look
like, and what you want.