Data Formatting - 2 questions into 1

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

Data Formatting - 2 questions into 1

Colin Valdiserri

Hello everyone,

 

This one has been racking my brain and I don’t know if it can be done, but was hoping someone on here might have an idea…

 

In a survey, respondents were asked which brand they use as one question. They were also asked which brand they would consider in another question. They were then asked to rate each of the 2 brands on 19 attributes using a 1-5 scale. My problem is that in the data I have the following 4 variables:

·         1stbrand à The brand the respondent used

·         2ndbrand à The brad the respondent would consider

·         Q18_1 through Q18_19 à Ratings from 1-5 on each of the 19 attributes

·         Q18a_1 through Q18a_19 à Ratings from 1-5 on each of the 19 attributes

 

Right now I have to run a “split file” on 1stbrand and the run descriptives on Q18_1 through Q18_19 to get the means for the attribute ratings by each brand that was used. Then I have to run a “split file” by 2ndbrand and run descriptives on Q18a_1 through Q18a_19 to get the means for the attribute ratings by each brand considered.

 

The problem is that I need aggregate results for each brand whether it was used or considered and I can’t figure out how to do this. Its driving me crazy, because I’m guessing there is any easy way to do it, but I can’t think of it.  

 

Any help will be greatly appreciated! Thank you in advance,

 

Colin

 

 

Colin M. Valdiserri

Informed Decisions Group, Inc.

8854 Jordan Court | North Ridgeville, Ohio | 44039
P: 440.935.5414
F: 440.353.0621

cvaldiserri@...
www.idg-consulting.com

 

The information and attachments contained in this e-mail message is intended for the use of the recipient(s) named above and is privileged and confidential. If you are not the intended recipient, you are formally notified that you have received this message in error and that any review, dissemination, distribution, or copying of the message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the original message.

 

Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Andy W
You could use VARSTOCASES to make 1stBrand and 2ndBrand in the same column then run the split file. This is annoying though as you need to map all of the "Q18_? Q18_a?" substatements to the same column. Something like this (untested);

VARSTOCASES
/MAKE Brand from Brand1 Brand2
/MAKE Q18_1 from Q18_1 Q18_a1
...
/MAKE Q18_19 from Q18_19 Q18_a19
/INDEX ID.

Note this restructuring it is probably easy to accidentally double count people, but if you split file by each brand individually (and no one person lists the same brand in the brand1 and brand2 columns) this will give you what you want I think.


Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Richard Ristow
In reply to this post by Colin Valdiserri
At 05:50 PM 9/11/2013, Colin Valdiserri wrote:

>In a survey, respondents were asked which brand
>they use as one question. They were also asked
>which brand they would consider in another
>question. They were then asked to rate each of
>the 2 brands on 19 attributes using a 1-5 scale.
>My problem is that in the data I have the following 4 variables:
>·         1stbrand à The brand the respondent used
>·         2ndbrand à The brad the respondent would consider
>·         Q18_1 through Q18_19 à Ratings from 1-5 on each of the 19 attributes
>·         Q18a_1 through Q18a_19 à Ratings from
>1-5 on each of the 19 attributes
>
>Right now I have to run a “split file” on
>1stbrand and the run descriptives on Q18_1
>through Q18_19 to get the means for the
>attribute ratings by each brand that was used.
>... I need aggregate results for each brand
>whether it was used or considered and I can’t figure out how to do this.

What you want is two records per respondent, organized like this:

1. Respondent or questionnaire ID. (If you don't
have any such ID already in the file, add sequence numbers.)

2. Indicator variable:
    1=respondent USED this brand;
    2=respondent WOULD CONSIDER this brand

3. Brand ID

4. Q18_1 through Q18_19 values

You can do this by a VARSTOCASES that would be
awkward to write (it would have to name every one
of the 40 variables, two brand IDs and 38
attribute ratings), though not so bad using the menus.

Is this enough to go on?

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Javier Figueroa
In reply to this post by Andy W
Esta es otra solución, pero cada marca en diferente columan y los atributos como casos. espero te sirva, saludos.

/*Aqui creamos un archivo temporal/ficticio.
data list list/id q1stbrand q2ndbrand Q18_1  Q18_2 Q18_3 Q18_4 Q18_5 Q18_6 Q18_7 Q18_8  Q18_9 Q18_10 Q18_11 Q18_12 Q18_13 Q18_14 Q18_15 Q18_16 Q18_17 Q18_18 Q18_19 
Q18a_1  Q18a_2 Q18a_3 Q18a_4 Q18a_5 Q18a_6 Q18a_7 Q18a_8  Q18a_9 Q18a_10 Q18a_11 Q18a_12 Q18a_13 Q18a_14 Q18a_15 Q18a_16 Q18a_17 Q18a_18 Q18a_19.
begin data
1 1 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3
2 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4 2
3 1 4 1 1 1 1 1 3 4 5 3 3 2 1 1 2 3 4 4 5 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 1
4 8 8 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4 
5 8 7 1 1 1 1 1 3 4 5 3 3 2 1 1 2 3 4 4 5 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 1
6 2 5 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4 2
end data.
dataset name BrandRatings.

/*Aqui generamos el archivo para poder hacer los agregados.
VARSTOCASES
  /ID=id1
  /MAKE q18BrandUsed FROM Q18_1 Q18_2 Q18_3 Q18_4 Q18_5 Q18_6 Q18_7 Q18_8 Q18_9 Q18_10 Q18_11 
    Q18_12 Q18_13 Q18_14 Q18_15 Q18_16 Q18_17 Q18_18 Q18_19
  /MAKE q18BrandConsider FROM Q18a_1 Q18a_2 Q18a_3 Q18a_4 Q18a_5 Q18a_6 Q18a_7 Q18a_8 Q18a_9 
    Q18a_10 Q18a_11 Q18a_12 Q18a_13 Q18a_14 Q18a_15 Q18a_16 Q18a_17 Q18a_18 Q18a_19
  /INDEX=Índice1(19) 
  /KEEP=id q1stbrand q2ndbrand 
  /NULL=KEEP.


Javier Figueroa.



2013/9/11 Andy W <[hidden email]>
You could use VARSTOCASES to make 1stBrand and 2ndBrand in the same column
then run the split file. This is annoying though as you need to map all of
the "Q18_? Q18_a?" substatements to the same column. Something like this
(untested);

VARSTOCASES
/MAKE Brand from Brand1 Brand2
/MAKE Q18_1 from Q18_1 Q18_a1
...
/MAKE Q18_19 from Q18_19 Q18_a19
/INDEX ID.

Note this restructuring it is probably easy to accidentally double count
people, but if you split file by each brand individually (and no one person
lists the same brand in the brand1 and brand2 columns) this will give you
what you want I think.






-----
Andy W
[hidden email]
http://andrewpwheeler.wordpress.com/
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Data-Formatting-2-questions-into-1-tp5721923p5721924.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



--
Javier Figueroa
Procesamiento y Análisis de bases de datos

Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

David Marso
Administrator
In reply to this post by Richard Ristow
"You can do this by a VARSTOCASES that would be
awkward to write (it would have to name every one
of the 40 variables, two brand IDs and 38
attribute ratings"

Actually FWIW; VARSTOCASES does support TO in variable lists!

Richard Ristow wrote
At 05:50 PM 9/11/2013, Colin Valdiserri wrote:

>In a survey, respondents were asked which brand
>they use as one question. They were also asked
>which brand they would consider in another
>question. They were then asked to rate each of
>the 2 brands on 19 attributes using a 1-5 scale.
>My problem is that in the data I have the following 4 variables:
>·         1stbrand à The brand the respondent used
>·         2ndbrand à The brad the respondent would consider
>·         Q18_1 through Q18_19 à Ratings from 1-5 on each of the 19 attributes
>·         Q18a_1 through Q18a_19 à Ratings from
>1-5 on each of the 19 attributes
>
>Right now I have to run a “split file” on
>1stbrand and the run descriptives on Q18_1
>through Q18_19 to get the means for the
>attribute ratings by each brand that was used.
>... I need aggregate results for each brand
>whether it was used or considered and I can’t figure out how to do this.

What you want is two records per respondent, organized like this:

1. Respondent or questionnaire ID. (If you don't
have any such ID already in the file, add sequence numbers.)

2. Indicator variable:
    1=respondent USED this brand;
    2=respondent WOULD CONSIDER this brand

3. Brand ID

4. Q18_1 through Q18_19 values

You can do this by a VARSTOCASES that would be
awkward to write (it would have to name every one
of the 40 variables, two brand IDs and 38
attribute ratings), though not so bad using the menus.

Is this enough to go on?

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Richard Ristow
At 08:23 PM 9/11/2013, David Marso responded to my note:

>>You can do this by a VARSTOCASES that would be awkward to write (it
>>would have to name every one of the 40 variables, two brand IDs and
>>38 attribute ratings"
>
>Actually FWIW; VARSTOCASES *does support TO* in variable lists!

It's worth a good deal, but not much in this case. The problem isn't
one MAKE clause with a lot of variables; it's a lot of MAKE clauses
with two variables each.

Here's the VARSTOCASE I came up with, using Javier Figueroa's test
data (many thanks, even if my approach is different). It's tested. I
don't see how to simplify it with 'TO'.

(And I apologize for suggesting the menus! The Restructure menu,
among other things, refuses to let you use the same name for a source
and target variable in MAKE, although, as you can see below,
VARSTOCASES allows that.)

VARSTOCASES
    /MAKE Brand  FROM q1stbrand q2ndbrand
    /MAKE Q18_1  FROM Q18_1  Q18a_1
    /MAKE Q18_2  FROM Q18_2  Q18a_2
    /MAKE Q18_3  FROM Q18_3  Q18a_3
    /MAKE Q18_4  FROM Q18_4  Q18a_4
    /MAKE Q18_5  FROM Q18_5  Q18a_5
    /MAKE Q18_6  FROM Q18_6  Q18a_6
    /MAKE Q18_7  FROM Q18_7  Q18a_7
    /MAKE Q18_8  FROM Q18_8  Q18a_8
    /MAKE Q18_9  FROM Q18_9  Q18a_9
    /MAKE Q18_10 FROM Q18_10 Q18a_10
    /MAKE Q18_11 FROM Q18_11 Q18a_11
    /MAKE Q18_12 FROM Q18_12 Q18a_12
    /MAKE Q18_13 FROM Q18_13 Q18a_13
    /MAKE Q18_14 FROM Q18_14 Q18a_14
    /MAKE Q18_15 FROM Q18_15 Q18a_15
    /MAKE Q18_16 FROM Q18_16 Q18a_16
    /MAKE Q18_17 FROM Q18_17 Q18a_17
    /MAKE Q18_18 FROM Q18_18 Q18a_18
    /MAKE Q18_19 FROM Q18_19 Q18a_19
    /INDEX = Role(2)
    /NULL = KEEP.

=======================================================
APPENDIX: Test data (from Javier Figueroa) and all code
=======================================================

NEW FILE.
data list list/
    id q1stbrand q2ndbrand
    Q18_1   Q18_2  Q18_3  Q18_4  Q18_5  Q18_6  Q18_7  Q18_8  Q18_9
    Q18_10  Q18_11 Q18_12 Q18_13 Q18_14 Q18_15 Q18_16 Q18_17
    Q18_18  Q18_19
    Q18a_1  Q18a_2 Q18a_3 Q18a_4 Q18a_5 Q18a_6 Q18a_7 Q18a_8 Q18a_9
    Q18a_10 Q18a_11 Q18a_12 Q18a_13 Q18a_14 Q18a_15 Q18a_16 Q18a_17
    Q18a_18 Q18a_19.
begin data
1 1 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4 2 3 1 2 3 1 2 1 2 2 3 4 4 3
2 2 3 4 5 3
2 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5
2 1 2 3 4 2
3 1 4 1 1 1 1 1 3 4 5 3 3 2 1 1 2 3 4 4 5 2 3 1 2 3 1 2 1 2 2 3 4 4 3
2 2 3 4 5 1
4 8 8 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4
5 2 1 2 3 4
5 8 7 1 1 1 1 1 3 4 5 3 3 2 1 1 2 3 4 4 5 2 3 1 2 3 1 2 1 2 2 3 4 4 3
2 2 3 4 5 1
6 2 5 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5
2 1 2 3 4 2
end data.

FORMATS ALL (F3).
VARIABLE WIDTH id (4).
VARIABLE WIDTH q1stbrand q2ndbrand (8).

VARIABLE WIDTH Q18_1  TO Q18_19  (7).
VARIABLE WIDTH Q18a_1 TO Q18a_19 (7).

dataset name     BrandRatings WINDOW=FRONT.

DATASET ACTIVATE BrandRatings WINDOW=FRONT.
DATASET COPY     Restructure.
DATASET ACTIVATE Restructure  WINDOW=FRONT.

VARSTOCASES
    /MAKE Brand  FROM q1stbrand q2ndbrand
    /MAKE Q18_1  FROM Q18_1  Q18a_1
    /MAKE Q18_2  FROM Q18_2  Q18a_2
    /MAKE Q18_3  FROM Q18_3  Q18a_3
    /MAKE Q18_4  FROM Q18_4  Q18a_4
    /MAKE Q18_5  FROM Q18_5  Q18a_5
    /MAKE Q18_6  FROM Q18_6  Q18a_6
    /MAKE Q18_7  FROM Q18_7  Q18a_7
    /MAKE Q18_8  FROM Q18_8  Q18a_8
    /MAKE Q18_9  FROM Q18_9  Q18a_9
    /MAKE Q18_10 FROM Q18_10 Q18a_10
    /MAKE Q18_11 FROM Q18_11 Q18a_11
    /MAKE Q18_12 FROM Q18_12 Q18a_12
    /MAKE Q18_13 FROM Q18_13 Q18a_13
    /MAKE Q18_14 FROM Q18_14 Q18a_14
    /MAKE Q18_15 FROM Q18_15 Q18a_15
    /MAKE Q18_16 FROM Q18_16 Q18a_16
    /MAKE Q18_17 FROM Q18_17 Q18a_17
    /MAKE Q18_18 FROM Q18_18 Q18a_18
    /MAKE Q18_19 FROM Q18_19 Q18a_19
    /INDEX = Role(2)
    /NULL = KEEP.

VARIABLE WIDTH Role Brand        (5).
VARIABLE WIDTH Q18_1  TO Q18_19  (6).

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Rich Ulrich
In reply to this post by Colin Valdiserri
Before there was VARSTOCASES, there was  XSAVE/rename ....
which I used a lot, back in the olden days.  It looks like here is an
instance where it might be more compact and readable.

You can use Datasets instead of files, and the syntax goes something like this.

XSAVE outfile= temp1/keep= brand2, Q18a_1 to Q18a19
 /rename= (brand2 Q18a_1 to Q18a_19 = (brand Q18_1 to Q18_19) .
SAVE outfile= temp2/keep= brand1 Q18_1 to Q18_10/rename= (brand1=brand).

Then ADD FILES.

You could do this with two SAVE procedures, but the XSAVE is performed
without an additional pass through the data.

--
Rich Ulrich



Date: Wed, 11 Sep 2013 17:50:33 -0400
From: [hidden email]
Subject: Data Formatting - 2 questions into 1
To: [hidden email]

Hello everyone,

 

This one has been racking my brain and I don’t know if it can be done, but was hoping someone on here might have an idea…

 

In a survey, respondents were asked which brand they use as one question. They were also asked which brand they would consider in another question. They were then asked to rate each of the 2 brands on 19 attributes using a 1-5 scale. My problem is that in the data I have the following 4 variables:

·         1stbrand à The brand the respondent used

·         2ndbrand à The brad the respondent would consider

·         Q18_1 through Q18_19 à Ratings from 1-5 on each of the 19 attributes

·         Q18a_1 through Q18a_19 à Ratings from 1-5 on each of the 19 attributes

 

Right now I have to run a “split file” on 1stbrand and the run descriptives on Q18_1 through Q18_19 to get the means for the attribute ratings by each brand that was used. Then I have to run a “split file” by 2ndbrand and run descriptives on Q18a_1 through Q18a_19 to get the means for the attribute ratings by each brand considered.

 

The problem is that I need aggregate results for each brand whether it was used or considered and I can’t figure out how to do this. Its driving me crazy, because I’m guessing there is any easy way to do it, but I can’t think of it.  

 

Any help will be greatly appreciated! Thank you in advance,

 

Colin

 

 

Colin M. Valdiserri

Informed Decisions Group, Inc.

8854 Jordan Court | North Ridgeville, Ohio | 44039
P: 440.935.5414
F: 440.353.0621

cvaldiserri@...
www.idg-consulting.com

 

The information and attachments contained in this e-mail message is intended for the use of the recipient(s) named above and is privileged and confidential. If you are not the intended recipient, you are formally notified that you have received this message in error and that any review, dissemination, distribution, or copying of the message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the original message.

 

Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Richard Ristow
At 10:41 AM 9/12/2013, Rich Ulrich wrote:

>[This] looks like an instance where [SAVE and XSAVE, with RENAME]
>might be more compact and readable.
>
>XSAVE outfile= temp1/keep= brand2, Q18a_1 to Q18a19
>  /rename= (brand2 Q18a_1 to Q18a_19 = (brand Q18_1 to Q18_19) .
>SAVE outfile= temp2/keep= brand1 Q18_1 to Q18_10/rename= (brand1=brand).

Nice!

>You can use Datasets instead of files, ...

Is this true? For reasons that seemed good to SPSS(*), most commands
that reference save-form files can also reference datasets; but, at
least initially, GET, SAVE, and XSAVE could not. I haven't heard that
that's been changed.
=========================================================
(*)
Date:         Mon, 24 Apr 2006 08:10:56 -0500
From:     "Peck, Jon" <[hidden email]>
Subject:  Re: DATASET DECLARE?
To:       [hidden email]
X-ELNK-Info: spv=0;
X-ELNK-AV: 0
X-ELNK-Info: sbv=0; sbrc=.0; sbf=0b; sbw=000;

DATASET DECLARE ... is not honored by SAVE or XSAVE [because] that
would not save the file: SAVE dataset would just create another
unsaved dataset.  We felt that this behavior, while sometimes
convenient, would confuse users into thinking that they had actually
saved their file this way.

A dataset is not a file, is not a file, is not a file...

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Jon K Peck
XSAVE and SAVE still cannot write to datasets, only files and for the same reasons.


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        Richard Ristow <[hidden email]>
To:        [hidden email],
Date:        09/12/2013 11:25 AM
Subject:        Re: [SPSSX-L] Data Formatting - 2 questions into 1
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




At 10:41 AM 9/12/2013, Rich Ulrich wrote:

>[This] looks like an instance where [SAVE and XSAVE, with RENAME]
>might be more compact and readable.
>
>XSAVE outfile= temp1/keep= brand2, Q18a_1 to Q18a19
>  /rename= (brand2 Q18a_1 to Q18a_19 = (brand Q18_1 to Q18_19) .
>SAVE outfile= temp2/keep= brand1 Q18_1 to Q18_10/rename= (brand1=brand).

Nice!

>You can use Datasets instead of files, ...

Is this true? For reasons that seemed good to SPSS(*), most commands
that reference save-form files can also reference datasets; but, at
least initially, GET, SAVE, and XSAVE could not. I haven't heard that
that's been changed.
=========================================================
(*)
Date:         Mon, 24 Apr 2006 08:10:56 -0500
From:     "Peck, Jon" <[hidden email]>
Subject:  Re: DATASET DECLARE?
To:       [hidden email]
X-ELNK-Info: spv=0;
X-ELNK-AV: 0
X-ELNK-Info: sbv=0; sbrc=.0; sbf=0b; sbw=000;

DATASET DECLARE ... is not honored by SAVE or XSAVE [because] that
would not save the file: SAVE dataset would just create another
unsaved dataset.  We felt that this behavior, while sometimes
convenient, would confuse users into thinking that they had actually
saved their file this way.

A dataset is not a file, is not a file, is not a file...

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD


Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Richard Ristow
In reply to this post by Rich Ulrich
Sorry -- a postscript

At 10:41 AM 9/12/2013, Rich Ulrich wrote:

>[The more-compact] syntax goes something like this:
>
>XSAVE outfile= temp1/keep= brand2, Q18a_1 to Q18a19
>  /rename= (brand2 Q18a_1 to Q18a_19 = (brand Q18_1 to Q18_19) .
>SAVE outfile= temp2/keep= brand1 Q18_1 to Q18_10/rename= (brand1=brand).
>Then ADD FILES.

That suggests what would be a nice enhancement to VARSTOCASES: accept
variable lists as the *target* of MAKE clauses. That would allow the
VARSTOCASES I previously posted to be shortened like this:

VARSTOCASES
    /MAKE Brand  FROM q1stbrand q2ndbrand
    /MAKE Q18_1 to Q18_19
     FROM Q18_1 to Q18a_1, Q18a_1 to Q18a_19
   /INDEX = Role(2)
    /NULL = KEEP.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Rich Ulrich
In reply to this post by Jon K Peck
Sorry - that was a careless assumption on my part.  I should
have raised it as a question.

Reserving (X)SAVE for actually writing out files seems like
a good idea.

--
Rich Ulrich

Date: Thu, 12 Sep 2013 11:43:25 -0600
From: [hidden email]
Subject: Re: Data Formatting - 2 questions into 1
To: [hidden email]

XSAVE and SAVE still cannot write to datasets, only files and for the same reasons.


...[snip previous]
Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Bruce Weaver
Administrator
In reply to this post by Rich Ulrich
Here's an example of Rich U's approach using Javier's sample data and some code borrowed from Richard R.


NEW FILE.
DATASET CLOSE all.

* Use Javier's sample data.
data list list /
 id q1stbrand q2ndbrand Q18_1  to Q18_19  Q18a_1 to Q18a_19.
begin data
1 1 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3
2 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4 2
3 1 4 1 1 1 1 1 3 4 5 3 3 2 1 1 2 3 4 4 5 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 1
4 8 8 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4
5 8 7 1 1 1 1 1 3 4 5 3 3 2 1 1 2 3 4 4 5 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 1
6 2 5 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4 2
end data.

FORMATS ALL (F3).
VARIABLE WIDTH
 id (4) /
 q1stbrand q2ndbrand (8) /
 Q18_1  TO Q18_19 Q18a_1 TO Q18a_19 (7).


XSAVE OUTFILE = "C:\Temp\Brand1.sav" /
 keep =  ID q1stbrand Q18_1 to Q18_19 / rename (q1stbrand = Brand).

SAVE OUTFILE = "C:\Temp\Brand2.sav" /
 keep = ID q2ndbrand Q18a_1 to Q18a_19 /
 rename (q2ndbrand Q18a_1 to Q18a_19 = Brand Q18_1 to Q18_19).

ADD FILES
 File = "C:\Temp\Brand1.sav" / IN = Role /
 File = "C:\Temp\Brand2.sav" / BY ID .
EXECUTE.

RECODE Role (0=2) (else = copy).
EXECUTE.



Rich Ulrich wrote
Before there was VARSTOCASES, there was  XSAVE/rename ....
which I used a lot, back in the olden days.  It looks like here is an
instance where it might be more compact and readable.

You can use Datasets instead of files, and the syntax goes something like this.

XSAVE outfile= temp1/keep= brand2, Q18a_1 to Q18a19
 /rename= (brand2 Q18a_1 to Q18a_19 = (brand Q18_1 to Q18_19) .
SAVE outfile= temp2/keep= brand1 Q18_1 to Q18_10/rename= (brand1=brand).

Then ADD FILES.

You could do this with two SAVE procedures, but the XSAVE is performed
without an additional pass through the data.

--
Rich Ulrich


Date: Wed, 11 Sep 2013 17:50:33 -0400
From: [hidden email]
Subject: Data Formatting - 2 questions into 1
To: [hidden email]

Hello everyone,  This one has been racking my brain and I don’t know if it can be done, but was hoping someone on here might have an idea…  In a survey, respondents were asked which brand they use as one question. They were also asked which brand they would consider in another question. They were then asked to rate each of the 2 brands on 19 attributes using a 1-5 scale. My problem is that in the data I have the following 4 variables:·         1stbrand à The brand the respondent used·         2ndbrand à The brad the respondent would consider·         Q18_1 through Q18_19 à Ratings from 1-5 on each of the 19 attributes·         Q18a_1 through Q18a_19 à Ratings from 1-5 on each of the 19 attributes Right now I have to run a “split file” on 1stbrand and the run descriptives on Q18_1 through Q18_19 to get the means for the attribute ratings by each brand that was used. Then I have to run a “split file” by 2ndbrand and run descriptives on Q18a_1 through Q18a_19 to get the means for the attribute ratings by each brand considered.  The problem is that I need aggregate results for each brand whether it was used or considered and I can’t figure out how to do this. Its driving me crazy, because I’m guessing there is any easy way to do it, but I can’t think of it.   Any help will be greatly appreciated! Thank you in advance,  Colin  Colin M. Valdiserri Informed Decisions Group, Inc.8854 Jordan Court | North Ridgeville, Ohio | 44039
P: 440.935.5414
F: 440.353.0621 [hidden email]
www.idg-consulting.com  The information and attachments contained in this e-mail message is intended for the use of the recipient(s) named above and is privileged and confidential. If you are not the intended recipient, you are formally notified that you have received this message in error and that any review, dissemination, distribution, or copying of the message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the original message.
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

Art Kendall
In reply to this post by Rich Ulrich
Perhaps a new kind of XSAVE such as DSXSAVE? could be created?
Art Kendall
Social Research Consultants
On 9/12/2013 3:34 PM, Rich Ulrich [via SPSSX Discussion] wrote:
Sorry - that was a careless assumption on my part.  I should
have raised it as a question.

Reserving (X)SAVE for actually writing out files seems like
a good idea.

--
Rich Ulrich

Date: Thu, 12 Sep 2013 11:43:25 -0600
From: [hidden email]
Subject: Re: Data Formatting - 2 questions into 1
To: [hidden email]

XSAVE and SAVE still cannot write to datasets, only files and for the same reasons.


...[snip previous]



If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Data-Formatting-2-questions-into-1-tp5721923p5721943.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Data Formatting - 2 questions into 1

David Marso
Administrator
In reply to this post by Richard Ristow
How about a little help from our old friend MATRIX?
Using Richard's data.

DATASET DECLARE reshape .
MATRIX.
GET ID / FILR * / VAR ID .
GET brands / FILE * / VAR q1stbrand q2ndbrand .
GET Ratings / FILE * / VAR Q18_1 TO Q18a_19 .
COMPUTE XX={KRONEKER(ID,{1;1}), RESHAPE(brands,2*NROW(ID),1), RESHAPE(Ratings,2*NROW(ID),NCOL(Ratings)/2)} .
SAVE XX /OUTFILE reshape /VARIABLES  ID Brand Rate01 TO Rate19.
END MATRIX.

Richard Ristow wrote
At 08:23 PM 9/11/2013, David Marso responded to my note:

>>You can do this by a VARSTOCASES that would be awkward to write (it
>>would have to name every one of the 40 variables, two brand IDs and
>>38 attribute ratings"
>
>Actually FWIW; VARSTOCASES *does support TO* in variable lists!

It's worth a good deal, but not much in this case. The problem isn't
one MAKE clause with a lot of variables; it's a lot of MAKE clauses
with two variables each.

Here's the VARSTOCASE I came up with, using Javier Figueroa's test
data (many thanks, even if my approach is different). It's tested. I
don't see how to simplify it with 'TO'.

(And I apologize for suggesting the menus! The Restructure menu,
among other things, refuses to let you use the same name for a source
and target variable in MAKE, although, as you can see below,
VARSTOCASES allows that.)

VARSTOCASES
    /MAKE Brand  FROM q1stbrand q2ndbrand
    /MAKE Q18_1  FROM Q18_1  Q18a_1
    /MAKE Q18_2  FROM Q18_2  Q18a_2
    /MAKE Q18_3  FROM Q18_3  Q18a_3
    /MAKE Q18_4  FROM Q18_4  Q18a_4
    /MAKE Q18_5  FROM Q18_5  Q18a_5
    /MAKE Q18_6  FROM Q18_6  Q18a_6
    /MAKE Q18_7  FROM Q18_7  Q18a_7
    /MAKE Q18_8  FROM Q18_8  Q18a_8
    /MAKE Q18_9  FROM Q18_9  Q18a_9
    /MAKE Q18_10 FROM Q18_10 Q18a_10
    /MAKE Q18_11 FROM Q18_11 Q18a_11
    /MAKE Q18_12 FROM Q18_12 Q18a_12
    /MAKE Q18_13 FROM Q18_13 Q18a_13
    /MAKE Q18_14 FROM Q18_14 Q18a_14
    /MAKE Q18_15 FROM Q18_15 Q18a_15
    /MAKE Q18_16 FROM Q18_16 Q18a_16
    /MAKE Q18_17 FROM Q18_17 Q18a_17
    /MAKE Q18_18 FROM Q18_18 Q18a_18
    /MAKE Q18_19 FROM Q18_19 Q18a_19
    /INDEX = Role(2)
    /NULL = KEEP.

=======================================================
APPENDIX: Test data (from Javier Figueroa) and all code
=======================================================

NEW FILE.
data list list/
    id q1stbrand q2ndbrand
    Q18_1   Q18_2  Q18_3  Q18_4  Q18_5  Q18_6  Q18_7  Q18_8  Q18_9
    Q18_10  Q18_11 Q18_12 Q18_13 Q18_14 Q18_15 Q18_16 Q18_17
    Q18_18  Q18_19
    Q18a_1  Q18a_2 Q18a_3 Q18a_4 Q18a_5 Q18a_6 Q18a_7 Q18a_8 Q18a_9
    Q18a_10 Q18a_11 Q18a_12 Q18a_13 Q18a_14 Q18a_15 Q18a_16 Q18a_17
    Q18a_18 Q18a_19.
begin data
1 1 1 2 1 2 3 4 3 2 1 4 3 2 4 5 2 1 2 3 4 2 3 1 2 3 1 2 1 2 2 3 4 4 3
2 2 3 4 5 3
2 2 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5
2 1 2 3 4 2
3 1 4 1 1 1 1 1 3 4 5 3 3 2 1 1 2 3 4 4 5 2 3 1 2 3 1 2 1 2 2 3 4 4 3
2 2 3 4 5 1
4 8 8 3 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4
5 2 1 2 3 4
5 8 7 1 1 1 1 1 3 4 5 3 3 2 1 1 2 3 4 4 5 2 3 1 2 3 1 2 1 2 2 3 4 4 3
2 2 3 4 5 1
6 2 5 1 2 3 1 2 1 2 2 3 4 4 3 2 2 3 4 5 3 1 2 1 2 3 4 3 2 1 4 3 2 4 5
2 1 2 3 4 2
end data.

FORMATS ALL (F3).
VARIABLE WIDTH id (4).
VARIABLE WIDTH q1stbrand q2ndbrand (8).

VARIABLE WIDTH Q18_1  TO Q18_19  (7).
VARIABLE WIDTH Q18a_1 TO Q18a_19 (7).

dataset name     BrandRatings WINDOW=FRONT.

DATASET ACTIVATE BrandRatings WINDOW=FRONT.
DATASET COPY     Restructure.
DATASET ACTIVATE Restructure  WINDOW=FRONT.

VARSTOCASES
    /MAKE Brand  FROM q1stbrand q2ndbrand
    /MAKE Q18_1  FROM Q18_1  Q18a_1
    /MAKE Q18_2  FROM Q18_2  Q18a_2
    /MAKE Q18_3  FROM Q18_3  Q18a_3
    /MAKE Q18_4  FROM Q18_4  Q18a_4
    /MAKE Q18_5  FROM Q18_5  Q18a_5
    /MAKE Q18_6  FROM Q18_6  Q18a_6
    /MAKE Q18_7  FROM Q18_7  Q18a_7
    /MAKE Q18_8  FROM Q18_8  Q18a_8
    /MAKE Q18_9  FROM Q18_9  Q18a_9
    /MAKE Q18_10 FROM Q18_10 Q18a_10
    /MAKE Q18_11 FROM Q18_11 Q18a_11
    /MAKE Q18_12 FROM Q18_12 Q18a_12
    /MAKE Q18_13 FROM Q18_13 Q18a_13
    /MAKE Q18_14 FROM Q18_14 Q18a_14
    /MAKE Q18_15 FROM Q18_15 Q18a_15
    /MAKE Q18_16 FROM Q18_16 Q18a_16
    /MAKE Q18_17 FROM Q18_17 Q18a_17
    /MAKE Q18_18 FROM Q18_18 Q18a_18
    /MAKE Q18_19 FROM Q18_19 Q18a_19
    /INDEX = Role(2)
    /NULL = KEEP.

VARIABLE WIDTH Role Brand        (5).
VARIABLE WIDTH Q18_1  TO Q18_19  (6).

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"