Hello all, good morning. I am trying to reshape a data from wide to long to use for a GENLIN model. Each respondent in the data was asked to name 3 associates who they ask for help (named Fr1, Fr2, Fr3) and 3 others who they seek advice from (Sis1, Sis2, Sis3). They were also asked to provide a number of information about each associates, for example, their age (Fr1_Age....Sis3_Age). Respondents also report their Age, Gender, etc (called R_Age, R_Gender). I want to reshape the data from wide to long, as shown in the image posted here: https://ibb.co/bBVpoQ. I am able to do it for one of the relations, using the following command: VARSTOCASES /MAKE trans1 FROM Fr_Alters_1 Fr_Alters_2 Fr_Alters_3 /MAKE trans2 FROM Age1 Age2 Age3 /INDEX=Index1(3) /KEEP=id R_Age1 R_Age2 R_Age3 Relation1 Relation2 Relation3 /NULL=KEEP. However, I am not been successful in getting the command to reproduce the two relations at the same time. I will appreciate some help from you all in accomplishing this. thanks - Cy ----------------------------------------------------- |
Administrator
|
The VARSTOCASES command reshapes data from WIDE to LONG.
You are barking up the wrong tree. CASESTOVARS is the appropriate command to go from LONG to WIDE. AGGREGATE following VECTOR and COMPUTE will also suffice. data: id index x y z 1 1 a 1 4 1 2 b 3 6 1 3 c 4 2 2 1 a 2 4 2 2 b 1 2 2 3 c 4 5 VECTOR x (3,A1) /y (3,F1) /z (3,F1). COMPUTE x(index)=x. COMPUTE y(index)=y. COMPUTE z(index)=z. AGGREGATE OUTFILE * / BREAK id / x1 TO x3 y1 TO y3 z1 TO z3 = MAX(x1 TO x3 y1 TO y3 z1 TO z3 ). Yields: id x1 TO x3 y1 TO y3 z1 TO z3 1 a b c 1 3 4 4 6 2 2 a b c 2 1 4 4 2 5
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?" |
Administrator
|
You lost me there, David. The image file the OP referred to *does* show the original file as WIDE and the final file as LONG.
To the OP, people may be reluctant to click on links like the one you provided. It is better to provide short text listings of the original and final data files (e.g., using DATA LIST, as David did in his reply). I don't have SPSS on this machine, so cannot test right now. But I think you want something like the following (given the images you posted): VARSTOCASES /MAKE CONTACTS FROM Fr1 to Fr3 Sis1 to Sis3 /MAKE ContactAge FROM Fr1_Age to Fr3_Age Sis1_Age to Sis3_Age /INDEX=ContactID(6) /KEEP=id R_Age R_Gender /NULL=KEEP. COMPUTE Friend = ContactID LT 4. COMPUTE Sister = ContactID GT 3. STRING Tie_ID (A8). COMPUTE Tie_ID = CONCAT(STRING(ID,F5.0),"_",STRING(ContactID,F1.0)). FORMATS Friend Sister (F1). LIST. The ContactAge variable is not shown in your LONG final file, but you probably want to include that info. HTH.
--
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/). |
Administrator
|
I am basing my comment on the Subject line and the extra records in the Long file which don't appear in the wide file. On Sun, Jun 18, 2017 at 9:03 AM, Bruce Weaver [via SPSSX Discussion] <[hidden email]> wrote: You lost me there, David. The image file the OP referred to *does* show the original file as WIDE and the final file as LONG.
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?" |
Administrator
|
I suppose you're referring to that subject line up there, are you? The one I did not pay much attention to until now.
I think the OP needs to clarify what they are trying to do exactly, and whether anything that has been suggested so far helps.
--
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/). |
Free forum by Nabble | Edit this page |