Re: How to rotate a base

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: How to rotate a base

David Marso
Administrator
Rather than going WIDE to LONG, SORT, then LONG to WIDE:
Possibly use AUTORECODE with / GROUP on the product variables.
Use results as INDEX to populate vectors and AGGREGATE.
My prehistoric version of SPSS (11.5) doesn't support /GROUP so this syntax
is just a guess.

AUTORECODE prod_1 prod_2...prod_n
         /INTO I_1 I_2...I_n
         /GROUP.
VECTOR EVAL (N) /PROD(N).
DO REPEAT I=I_1 TO I_N
         /P=Prod_1 Prod_2...Prod_N
         /E=EVal_1 Eval_2...Eval_n.
COMPUTE PROD(I)=P.
COMPUTE EVAL(I)=E.
AGGREGATE OUTFILE *
         /BREAK ID
         /PROD_1 EVAL_1 .... PROD_N EVAL_N
     =MAX(PROD_1 EVAL_1 .... PROD_N EVAL_N).

Have no way to test this but it will work if OP does the homework.
IOW: No need to splatter the data, reorder and unsplatter ;-)
This might be more "code" than
VARSTOCASES .
SORT.
CASESTOVARS.
(6 lines vs 3), but is likely to be more efficient .
-Someone should test to verify this over various sizes of files-
Since I have no idea whether these are string or numeric variables, OP
should adjust as necessary (ie RTFM on the VECTOR command for declaring
strings -VECTOR V(N,A##)!!!)

If one were to go totally oldskool -say pre VARSTOCASES AND CASESTOVARS.
This could be done using XSAVE, AUTORECODE, VECTOR and AGGREGATE.
HTH, David



On Sun, 8 Aug 2010 20:48:28 -0400, Richard Ristow <[hidden email]>
wrote:

><html>
><body>
>At 02:36 AM 8/3/2010, Alexandra Chirilov wrote:<br><br>
><blockquote type=cite class=cite cite="">
><font face="Arial, Helvetica" size=2>Have someone a syntax which would
>help me to rotate a database in SPSS?<br>
>My database show like this:<br>
></font><br>
><font face="Arial, Helvetica" size=2>Respondent1&nbsp;&nbsp;&nbsp;
>Product A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Evaluation for prod
>A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Product B&nbsp;&nbsp;&nbsp; Evaluation
>for product B&nbsp;&nbsp; <br>
>Respondent2&nbsp;&nbsp;&nbsp; Product B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>Evaluation for prod B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Product
>A&nbsp;&nbsp;&nbsp; Evaluation for product A </font></blockquote><br>
>Or, shortening the values and reading the data as SPSS variables (and
>correcting Respondent4s 4 and 5, each of whom had the same product
>entered more than once):<br>
><font size=1>
>|-----------------------------|---------------------------|<br>
>|Output
>Created&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>|08-AUG-2010 20:34:59&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
>|-----------------------------|---------------------------|<br>
>Respondent&nbsp; Prod01 Eval01 Prod02 Eval02<br><br>
>Respondent1 Prod_A Eval A Prod_B Eval_B<br>
>Respondent2 Prod_B Eval_B Prod_A Eval_A<br>
>Respondent3 Prod_C Eval_C Prod_A Eval_A<br>
>Respondent4 Prod_C Eval_C Prod_X Eval_X<br>
>Respondent5 Prod_D Eval_D Prod_X Eval_X<br>
>Respondent6 Prod_A Eval_A Prod_B Eval_B<br><br>
>Number of cases read:&nbsp; 6&nbsp;&nbsp;&nbsp; Number of cases
>listed:&nbsp; 6<br><br>
></font><blockquote type=cite class=cite cite="">
><font face="Arial, Helvetica" size=2>And I need my database to look
>like:<br>
>&nbsp;<br>
>Respondent1&nbsp;&nbsp;&nbsp; Product A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>Evaluation for prod A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Product
>B&nbsp;&nbsp;&nbsp; Evaluation for product B&nbsp;&nbsp;
>���������</font><font face="Arial, Helvetica" size=2 color="#FF0000">
>(<i>I want to create specific columns for each attribute</i>)<br>
></font><font face="Arial, Helvetica" size=2>Respondent2&nbsp;&nbsp;&nbsp;
>Product A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Evaluation for prod
>A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Product B&nbsp;&nbsp;&nbsp; Evaluation
>for product B </font></blockquote><br>
>I'd do this with <tt><font size=2>VARSTOCASES, SORT, CASESTOVARS</font>.
>I've omitted the columns with &quot;Product A&quot;, &quot;Product
>B&quot;, etc., because the values in those columns can never vary within
>the data, except between product name and blank. Code is tested.<br><br>
><font size=2>VARSTOCASES<br>
>&nbsp;/MAKE Prod FROM Prod01 Prod02<br>
>&nbsp;/MAKE Eval FROM Eval01 Eval02<br>
>&nbsp;/KEEP =&nbsp; Respondent<br>
>&nbsp;/NULL = KEEP.<br><br>
>&nbsp;<br>
>Variables to Cases<br>
>|-----------------------------|---------------------------|<br>
>|Output
>Created&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>|08-AUG-2010 20:35:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
>|-----------------------------|---------------------------|<br>
>Generated Variables<br>
>|----|------|<br>
>|Name|Label |<br>
>|----|------|<br>
>|Prod|&lt;none&gt;|<br>
>|Eval|&lt;none&gt;|<br>
>|----|------|<br>
>Processing Statistics<br>
>|-------------|-|<br>
>|Variables In |5|<br>
>|Variables Out|3|<br>
>|-------------|-|<br><br>
>&nbsp;<br>
>SORT CASES BY Respondent Prod.<br>
>CASESTOVARS<br>
>&nbsp;/ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = Respondent<br>
>&nbsp;/INDEX&nbsp;&nbsp; = Prod<br>
>&nbsp;/GROUPBY = INDEX .<br><br>
>Cases to Variables<br>
>|-----------------------------|---------------------------|<br>
>|Output
>Created&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>|08-AUG-2010 20:35:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
>|-----------------------------|---------------------------|<br>
>Generated Variables<br>
>|--------|------|------|<br>
>|Original|Prod&nbsp; |Result|<br>
>|Variable|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |------|<br>
>|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |Name&nbsp; |<br>
>|--------|------|------|<br>
>|Eval&nbsp;&nbsp;&nbsp; |Prod_A|Prod_A|<br>
>|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |Prod_B|Prod_B|<br>
>|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |Prod_C|Prod_C|<br>
>|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |Prod_D|Prod_D|<br>
>|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |Prod_X|Prod_X|<br>
>|--------|------|------|<br>
>Processing Statistics<br>
>|---------------|---|<br>
>|Cases In&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |12 |<br>
>|Cases Out&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |6&nbsp; |<br>
>|---------------|---|<br>
>|Cases In/Cases |2.0|<br>
>|Out&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>|&nbsp;&nbsp; |<br>
>|---------------|---|<br>
>|Variables In&nbsp;&nbsp; |3&nbsp; |<br>
>|Variables Out&nbsp; |6&nbsp; |<br>
>|---------------|---|<br>
>|Index Values&nbsp;&nbsp; |5&nbsp; |<br>
>|---------------|---|<br><br>
>&nbsp;<br>
>LIST.<br><br>
>List<br>
>|-----------------------------|---------------------------|<br>
>|Output
>Created&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>|08-AUG-2010 20:35:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
>|-----------------------------|---------------------------|<br>
>Respondent&nbsp; Prod_A Prod_B Prod_C Prod_D Prod_X<br><br>
>Respondent1 Eval A Eval_B<br>
>Respondent2 Eval_A Eval_B<br>
>Respondent3 Eval_A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eval_C<br>
>Respondent4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>Eval_C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eval_X<br>
>Respondent5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>Eval_D Eval_X<br>
>Respondent6 Eval_A Eval_B<br><br>
>Number of cases read:&nbsp; 6&nbsp;&nbsp;&nbsp; Number of cases
>listed:&nbsp; 6<br><br>
></font></tt>=============================<br>
>APPENDIX: Test data, and code<br>
>=============================<br>
><tt><font size=2>DATA LIST FIXED/<br>
>&nbsp;&nbsp; Respondent 01-11 (A)<br>
>&nbsp;&nbsp; Prod01&nbsp;&nbsp;&nbsp;&nbsp; 14-19
>(A)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
>&nbsp;&nbsp; Eval01&nbsp;&nbsp;&nbsp;&nbsp; 26-31 (A)<br>
>&nbsp;&nbsp; Prod02&nbsp;&nbsp;&nbsp;&nbsp; 38-43
>(A)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
>&nbsp;&nbsp; Eval02&nbsp;&nbsp;&nbsp;&nbsp; 48-53 (A).<br><br>
>*---|---10----|---20----|---30----|---40----|---50----|---60.<br>
>BEGIN DATA<br>
>Respondent1&nbsp; Prod_A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eval
>A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Prod_B&nbsp;&nbsp;&nbsp; Eval_B<br>
>Respondent2&nbsp; Prod_B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>Eval_B&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Prod_A&nbsp;&nbsp;&nbsp; Eval_A<br>
>Respondent3&nbsp; Prod_C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>Eval_C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Prod_A&nbsp;&nbsp;&nbsp; Eval_A<br>
>Respondent4&nbsp; Prod_C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>Eval_C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Prod_X&nbsp;&nbsp;&nbsp; Eval_X<br>
>Respondent5&nbsp; Prod_D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>Eval_D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Prod_X&nbsp;&nbsp;&nbsp; Eval_X<br>
>Respondent6&nbsp; Prod_A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
>Eval_A&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Prod_B&nbsp;&nbsp;&nbsp; Eval_B<br>
>END DATA.<br><br>
>LIST.<br><br>
>VARSTOCASES&nbsp; <br>
>&nbsp;/MAKE Prod FROM Prod01 Prod02<br>
>&nbsp;/MAKE Eval FROM Eval01 Eval02<br>
>&nbsp;/KEEP =&nbsp; Respondent<br>
>&nbsp;/NULL = KEEP.<br><br>
>LIST.<br><br>
>SORT CASES BY Respondent Prod.<br><br>
>CASESTOVARS<br>
>&nbsp;/ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = Respondent<br>
>&nbsp;/INDEX&nbsp;&nbsp; = Prod<br>
>&nbsp;/GROUPBY = INDEX .<br><br>
>LIST.</font></body>
><br>
></html>
>
>====================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

=====================
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?"