Hello people, For a time series study on couples, we'd like to create new set of variables for each person corresponding to the "partner's score" on a set of variables. Couples were asked to make diary entries on their mood and other things, and we'd like to have a variable for the person's mood and then their partner's mood at the equivalent time, for example. We have a variable for each person's entry (1-60 entries), their couple (1-4 couples), and another variable just specifying whether they are member 1 or member 2 in that couple (a variable called 'member'). Then we have a set of 51 variables we'd like to examine. I've pasted in the syntax and then the error message below. Any help / ideas would be much appreciated! Many Thanks, Russell Deighton The syntax: vector v = happy TO both_unhelpaction. vector newvar(51). SORT CASES BY couple entry member (A). LOOP #n = 1 to 51. IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). END LOOP. EXECUTE. The error message: >Error # 4030 in column 23. Text: newvar >The operand appearing on the left side of the assignment operator (equals >sign) is not a known vector name or function name. >Execution of this command stops. IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >Error # 4030 in column 51. Text: newvar >The operand appearing on the left side of the assignment operator (equals >sign) is not a known vector name or function name. >Execution of this command stops. END LOOP. EXECUTE. |
Administrator
|
The VECTOR declarations must be placed AFTER the SORT CASES command.
I have no idea what this is supposed to do. IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). Definitely NOT what you intend. You might find it easier to do this using the MATRIX language. UNTESTED: SORT CASES BY couple entry member (A). MATRIX. GET ids /FILE */VARIABLES couple entry member. GET scores /FILE */VARIABLES happy TO both_unhelpaction. COMPUTE newvars=MAKE(NROW (scores),NCOL (scores),0). LOOP #=1 TO NROW (scores)-1. DO IF ids(#,1:2)= ids(#+1,1:2). COMPUTE newvars(#,:)=scores(#+1,:). COMPUTE newvars(#+1,:)=scores(#,:). END IF. END LOOP. SAVE {ids ,scores ,newvars} /OUTFILE * /VARIABLES couple entry member scores01 TO scores51 Othrscores01 TO Othrscores51. END MATRIX. RENAME VARIABLES (up to you here.......). <Could use APPLY DICTIONARY for these... VARIABLE LABELS... VALUE LABELS... <quote author="Russell Deighton"> Hello people, For a time series study on couples, we'd like to create new set of variables for each person corresponding to the "partner's score" on a set of variables. Couples were asked to make diary entries on their mood and other things, and we'd like to have a variable for the person's mood and then their partner's mood at the equivalent time, for example. We have a variable for each person's entry (1-60 entries), their couple (1-4 couples), and another variable just specifying whether they are member 1 or member 2 in that couple (a variable called 'member'). Then we have a set of 51 variables we'd like to examine. I've pasted in the syntax and then the error message below. Any help / ideas would be much appreciated! Many Thanks, Russell Deighton The syntax: vector v = happy TO both_unhelpaction. vector newvar(51). SORT CASES BY couple entry member (A). LOOP #n = 1 to 51. IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). END LOOP. EXECUTE. The error message: >Error # 4030 in column 23. Text: newvar >The operand appearing on the left side of the assignment operator (equals >sign) is not a known vector name or function name. >Execution of this command stops. IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >Error # 4030 in column 51. Text: newvar >The operand appearing on the left side of the assignment operator (equals >sign) is not a known vector name or function name. >Execution of this command stops. END LOOP. EXECUTE. ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@.UGA (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?" -- Sent from: http://spssx-discussion.1045642.n5.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
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
|
Might actually be much easier (and reliable) to do a DATASET copy ,rename
variables, recode member, sort and MATCH. again untested. SORT CASES BY couple entry member (A). DATASET NAME raw. DATASET COPY copy. DATASET ACTIVATE copy. RECODE member (1=2)(2=1). RENAME VARIABLES (happy TO both_unhelpaction=new01 TO new51). SORT CASES BY couple entry member. MATCH FILES FILE raw / FILE * / BY couple entry member. David Marso wrote > The VECTOR declarations must be placed AFTER the SORT CASES command. > I have no idea what this is supposed to do. > IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). > Definitely NOT what you intend. > You might find it easier to do this using the MATRIX language. > UNTESTED: > > SORT CASES BY couple entry member (A). > MATRIX. > GET ids /FILE */VARIABLES couple entry member. > GET scores /FILE */VARIABLES happy TO both_unhelpaction. > COMPUTE newvars=MAKE(NROW (scores),NCOL (scores),0). > LOOP #=1 TO NROW (scores)-1. > DO IF ids(#,1:2)= ids(#+1,1:2). > COMPUTE newvars(#,:)=scores(#+1,:). > COMPUTE newvars(#+1,:)=scores(#,:). > END IF. > END LOOP. > SAVE {ids ,scores ,newvars} > /OUTFILE * > /VARIABLES couple entry member scores01 TO scores51 Othrscores01 TO > Othrscores51. > END MATRIX. > > RENAME VARIABLES (up to you here.......). > <Could use APPLY DICTIONARY for these... > VARIABLE LABELS... > VALUE LABELS... > > &lt;quote author=&quot;Russell Deighton&quot;> > Hello people, > > For a time series study on couples, we'd like to create new set of > variables for each person corresponding to the "partner's score" on a set > of variables. > > Couples were asked to make diary entries on their mood and other things, > and we'd like to have a variable for the person's mood and then their > partner's mood at the equivalent time, for example. > > We have a variable for each person's entry (1-60 entries), their couple > (1-4 couples), and another variable just specifying whether they are > member > 1 or member 2 in that couple (a variable called 'member'). Then we have a > set of 51 variables we'd like to examine. > > I've pasted in the syntax and then the error message below. Any help / > ideas would be much appreciated! > > Many Thanks, > Russell Deighton > > The syntax: > > vector v = happy TO both_unhelpaction. > vector newvar(51). > SORT CASES BY couple entry member (A). > LOOP #n = 1 to 51. > IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). > IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). > END LOOP. > EXECUTE. > > The error message: > >>Error # 4030 in column 23. Text: newvar >>The operand appearing on the left side of the assignment operator (equals >>sign) is not a known vector name or function name. >>Execution of this command stops. > IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). > >>Error # 4030 in column 51. Text: newvar >>The operand appearing on the left side of the assignment operator (equals >>sign) is not a known vector name or function name. >>Execution of this command stops. > END LOOP. > EXECUTE. > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA (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?" > -- > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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?" -- Sent from: http://spssx-discussion.1045642.n5.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
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
|
Nice solution, David.
David Marso wrote > Might actually be much easier (and reliable) to do a DATASET copy ,rename > variables, recode member, sort and MATCH. > again untested. > > SORT CASES BY couple entry member (A). > DATASET NAME raw. > DATASET COPY copy. > DATASET ACTIVATE copy. > RECODE member (1=2)(2=1). > RENAME VARIABLES (happy TO both_unhelpaction=new01 TO new51). > SORT CASES BY couple entry member. > MATCH FILES FILE raw / FILE * / BY couple entry member. > > > > > David Marso wrote >> The VECTOR declarations must be placed AFTER the SORT CASES command. >> I have no idea what this is supposed to do. >> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >> Definitely NOT what you intend. >> You might find it easier to do this using the MATRIX language. >> UNTESTED: >> >> SORT CASES BY couple entry member (A). >> MATRIX. >> GET ids /FILE */VARIABLES couple entry member. >> GET scores /FILE */VARIABLES happy TO both_unhelpaction. >> COMPUTE newvars=MAKE(NROW (scores),NCOL (scores),0). >> LOOP #=1 TO NROW (scores)-1. >> DO IF ids(#,1:2)= ids(#+1,1:2). >> COMPUTE newvars(#,:)=scores(#+1,:). >> COMPUTE newvars(#+1,:)=scores(#,:). >> END IF. >> END LOOP. >> SAVE {ids ,scores ,newvars} >> /OUTFILE * >> /VARIABLES couple entry member scores01 TO scores51 Othrscores01 TO >> Othrscores51. >> END MATRIX. >> >> RENAME VARIABLES (up to you here.......). >> <Could use APPLY DICTIONARY for these... >> VARIABLE LABELS... >> VALUE LABELS... >> >> &lt;quote author=&quot;Russell Deighton&quot;> >> Hello people, >> >> For a time series study on couples, we'd like to create new set of >> variables for each person corresponding to the "partner's score" on a set >> of variables. >> >> Couples were asked to make diary entries on their mood and other things, >> and we'd like to have a variable for the person's mood and then their >> partner's mood at the equivalent time, for example. >> >> We have a variable for each person's entry (1-60 entries), their couple >> (1-4 couples), and another variable just specifying whether they are >> member >> 1 or member 2 in that couple (a variable called 'member'). Then we have a >> set of 51 variables we'd like to examine. >> >> I've pasted in the syntax and then the error message below. Any help / >> ideas would be much appreciated! >> >> Many Thanks, >> Russell Deighton >> >> The syntax: >> >> vector v = happy TO both_unhelpaction. >> vector newvar(51). >> SORT CASES BY couple entry member (A). >> LOOP #n = 1 to 51. >> IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). >> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >> END LOOP. >> EXECUTE. >> >> The error message: >> >>>Error # 4030 in column 23. Text: newvar >>>The operand appearing on the left side of the assignment operator (equals >>>sign) is not a known vector name or function name. >>>Execution of this command stops. >> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >> >>>Error # 4030 in column 51. Text: newvar >>>The operand appearing on the left side of the assignment operator (equals >>>sign) is not a known vector name or function name. >>>Execution of this command stops. >> END LOOP. >> EXECUTE. >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to >> LISTSERV@.UGA (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?" >> -- >> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (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?" > -- > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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 ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- Sent from: http://spssx-discussion.1045642.n5.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
--
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
|
Thanks Bruce,
How about a little refinement using python ;-) This just does the RENAME portion. Everything else as is. Probably more elegant solutions than my crude python hack. begin program. import spssaux v=spssaux.VariableDict() newlist='' oldlist='' for ex in v.expand(["happy","TO","both_unhelpaction"]) : newlist=newlist+ex+'_new ' oldlist=oldlist+ex+' ' spss.Submit ('RENAME VARIABLES (' + oldlist + '=' + newlist + ').') end program. Bruce Weaver wrote > Nice solution, David. > > > David Marso wrote >> Might actually be much easier (and reliable) to do a DATASET copy ,rename >> variables, recode member, sort and MATCH. >> again untested. >> >> SORT CASES BY couple entry member (A). >> DATASET NAME raw. >> DATASET COPY copy. >> DATASET ACTIVATE copy. >> RECODE member (1=2)(2=1). >> RENAME VARIABLES (happy TO both_unhelpaction=new01 TO new51). >> SORT CASES BY couple entry member. >> MATCH FILES FILE raw / FILE * / BY couple entry member. >> >> >> >> >> David Marso wrote >>> The VECTOR declarations must be placed AFTER the SORT CASES command. >>> I have no idea what this is supposed to do. >>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >>> Definitely NOT what you intend. >>> You might find it easier to do this using the MATRIX language. >>> UNTESTED: >>> >>> SORT CASES BY couple entry member (A). >>> MATRIX. >>> GET ids /FILE */VARIABLES couple entry member. >>> GET scores /FILE */VARIABLES happy TO both_unhelpaction. >>> COMPUTE newvars=MAKE(NROW (scores),NCOL (scores),0). >>> LOOP #=1 TO NROW (scores)-1. >>> DO IF ids(#,1:2)= ids(#+1,1:2). >>> COMPUTE newvars(#,:)=scores(#+1,:). >>> COMPUTE newvars(#+1,:)=scores(#,:). >>> END IF. >>> END LOOP. >>> SAVE {ids ,scores ,newvars} >>> /OUTFILE * >>> /VARIABLES couple entry member scores01 TO scores51 Othrscores01 TO >>> Othrscores51. >>> END MATRIX. >>> >>> RENAME VARIABLES (up to you here.......). >>> <Could use APPLY DICTIONARY for these... >>> VARIABLE LABELS... >>> VALUE LABELS... >>> >>> &lt;quote author=&quot;Russell Deighton&quot;> >>> Hello people, >>> >>> For a time series study on couples, we'd like to create new set of >>> variables for each person corresponding to the "partner's score" on a >>> set >>> of variables. >>> >>> Couples were asked to make diary entries on their mood and other things, >>> and we'd like to have a variable for the person's mood and then their >>> partner's mood at the equivalent time, for example. >>> >>> We have a variable for each person's entry (1-60 entries), their couple >>> (1-4 couples), and another variable just specifying whether they are >>> member >>> 1 or member 2 in that couple (a variable called 'member'). Then we have >>> a >>> set of 51 variables we'd like to examine. >>> >>> I've pasted in the syntax and then the error message below. Any help / >>> ideas would be much appreciated! >>> >>> Many Thanks, >>> Russell Deighton >>> >>> The syntax: >>> >>> vector v = happy TO both_unhelpaction. >>> vector newvar(51). >>> SORT CASES BY couple entry member (A). >>> LOOP #n = 1 to 51. >>> IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). >>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >>> END LOOP. >>> EXECUTE. >>> >>> The error message: >>> >>>>Error # 4030 in column 23. Text: newvar >>>>The operand appearing on the left side of the assignment operator >>>>sign) is not a known vector name or function name. >>>>Execution of this command stops. >>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >>> >>>>Error # 4030 in column 51. Text: newvar >>>>The operand appearing on the left side of the assignment operator (equals >>>>sign) is not a known vector name or function name. >>>>Execution of this command stops. >>> END LOOP. >>> EXECUTE. >>> >>> ===================== >>> To manage your subscription to SPSSX-L, send a message to >>> LISTSERV@.UGA (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?" >>> -- >>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >>> >>> ===================== >>> To manage your subscription to SPSSX-L, send a message to >> >>> LISTSERV@.UGA >> >>> (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?" >> -- >> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (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 > > > > > > ----- > -- > Bruce Weaver > bweaver@ > http://sites.google.com/a/lakeheadu.ca/bweaver/ > > "When all else fails, RTFM." > > NOTE: My Hotmail account is not monitored regularly. > To send me an e-mail, please use the address shown above. > > -- > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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?" -- Sent from: http://spssx-discussion.1045642.n5.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
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
|
Or how about an unholy marriage?
DEFINE !pairdata (!POS !CMDEND) SORT CASES BY couple entry member (A). DATASET NAME raw. DATASET COPY copy. DATASET ACTIVATE copy. RECODE member (1=2)(2=1). !1. SORT CASES BY couple entry member. MATCH FILES FILE raw / FILE * / BY couple entry member. !ENDDEFINE. begin program. import spssaux v=spssaux.VariableDict() newlist='' oldlist='' for ex in v.expand(["v1","TO","v2"]) : newlist=newlist+ex+'_new ' oldlist=oldlist+ex+' ' spss.Submit ('!Pairdata RENAME VARIABLES (' + oldlist + '=' + newlist + ').') end program. David Marso wrote > Thanks Bruce, > How about a little refinement using python ;-) > This just does the RENAME portion. > Everything else as is. > Probably more elegant solutions than my crude python hack. > > begin program. > import spssaux > v=spssaux.VariableDict() > newlist='' > oldlist='' > for ex in v.expand(["happy","TO","both_unhelpaction"]) : > newlist=newlist+ex+'_new ' > oldlist=oldlist+ex+' ' > spss.Submit ('RENAME VARIABLES (' + oldlist + '=' + newlist + ').') > end program. > > > Bruce Weaver wrote >> Nice solution, David. >> >> >> David Marso wrote >>> Might actually be much easier (and reliable) to do a DATASET copy >>> ,rename >>> variables, recode member, sort and MATCH. >>> again untested. >>> >>> SORT CASES BY couple entry member (A). >>> DATASET NAME raw. >>> DATASET COPY copy. >>> DATASET ACTIVATE copy. >>> RECODE member (1=2)(2=1). >>> RENAME VARIABLES (happy TO both_unhelpaction=new01 TO new51). >>> SORT CASES BY couple entry member. >>> MATCH FILES FILE raw / FILE * / BY couple entry member. >>> >>> >>> >>> >>> David Marso wrote >>>> The VECTOR declarations must be placed AFTER the SORT CASES command. >>>> I have no idea what this is supposed to do. >>>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >>>> Definitely NOT what you intend. >>>> You might find it easier to do this using the MATRIX language. >>>> UNTESTED: >>>> >>>> SORT CASES BY couple entry member (A). >>>> MATRIX. >>>> GET ids /FILE */VARIABLES couple entry member. >>>> GET scores /FILE */VARIABLES happy TO both_unhelpaction. >>>> COMPUTE newvars=MAKE(NROW (scores),NCOL (scores),0). >>>> LOOP #=1 TO NROW (scores)-1. >>>> DO IF ids(#,1:2)= ids(#+1,1:2). >>>> COMPUTE newvars(#,:)=scores(#+1,:). >>>> COMPUTE newvars(#+1,:)=scores(#,:). >>>> END IF. >>>> END LOOP. >>>> SAVE {ids ,scores ,newvars} >>>> /OUTFILE * >>>> /VARIABLES couple entry member scores01 TO scores51 Othrscores01 TO >>>> Othrscores51. >>>> END MATRIX. >>>> >>>> RENAME VARIABLES (up to you here.......). >>>> <Could use APPLY DICTIONARY for these... >>>> VARIABLE LABELS... >>>> VALUE LABELS... >>>> >>>> &lt;quote author=&quot;Russell Deighton&quot;> >>>> Hello people, >>>> >>>> For a time series study on couples, we'd like to create new set of >>>> variables for each person corresponding to the "partner's score" on a >>>> set >>>> of variables. >>>> >>>> Couples were asked to make diary entries on their mood and other >>>> things, >>>> and we'd like to have a variable for the person's mood and then their >>>> partner's mood at the equivalent time, for example. >>>> >>>> We have a variable for each person's entry (1-60 entries), their couple >>>> (1-4 couples), and another variable just specifying whether they are >>>> member >>>> 1 or member 2 in that couple (a variable called 'member'). Then we have >>>> a >>>> set of 51 variables we'd like to examine. >>>> >>>> I've pasted in the syntax and then the error message below. Any help / >>>> ideas would be much appreciated! >>>> >>>> Many Thanks, >>>> Russell Deighton >>>> >>>> The syntax: >>>> >>>> vector v = happy TO both_unhelpaction. >>>> vector newvar(51). >>>> SORT CASES BY couple entry member (A). >>>> LOOP #n = 1 to 51. >>>> IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). >>>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >>>> END LOOP. >>>> EXECUTE. >>>> >>>> The error message: >>>> >>>>>Error # 4030 in column 23. Text: newvar >>>>>The operand appearing on the left side of the assignment operator > (equals >>>>>sign) is not a known vector name or function name. >>>>>Execution of this command stops. >>>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >>>> >>>>>Error # 4030 in column 51. Text: newvar >>>>>The operand appearing on the left side of the assignment operator > (equals >>>>>sign) is not a known vector name or function name. >>>>>Execution of this command stops. >>>> END LOOP. >>>> EXECUTE. >>>> >>>> ===================== >>>> To manage your subscription to SPSSX-L, send a message to >>>> LISTSERV@.UGA (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?" >>>> -- >>>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >>>> >>>> ===================== >>>> To manage your subscription to SPSSX-L, send a message to >>> >>>> LISTSERV@.UGA >>> >>>> (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?" >>> -- >>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >>> >>> ===================== >>> To manage your subscription to SPSSX-L, send a message to >> >>> LISTSERV@.UGA >> >>> (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 >> >> >> >> >> >> ----- >> -- >> Bruce Weaver > >> bweaver@ > >> http://sites.google.com/a/lakeheadu.ca/bweaver/ >> >> "When all else fails, RTFM." >> >> NOTE: My Hotmail account is not monitored regularly. >> To send me an e-mail, please use the address shown above. >> >> -- >> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (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?" > -- > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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?" -- Sent from: http://spssx-discussion.1045642.n5.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
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?" |
In reply to this post by David Marso
Here's a slightly more ideomatic and perhaps more readable version of the Python code. Functionality is the same. begin program. import spssaux oldlist = spssaux.VariableDict().expand(["happy", "TO", "both_unhelpaction"]) newlist = [item + "_new" for item in oldlist] spss.Submit ('RENAME VARIABLES (%s = %s)' % (" ".join(oldlist), " ".join(newlist))) end program. On Mon, Oct 23, 2017 at 8:15 AM, David Marso <[hidden email]> wrote: Thanks Bruce, |
In reply to this post by R Deighton
I would follow this straight-forward logic: 1. XSAVE after IF and after ELSE to write 2 files, a separate file for each partner; 2. RENAME (during the save) the variables for partner 2 (or, for both); 3. Match the two files. - you see $SYSMIS if the other record was not there.
-- Rich Ulrich From: SPSSX(r) Discussion <[hidden email]> on behalf of R Deighton <[hidden email]>
Sent: Monday, October 23, 2017 7:29:39 PM To: [hidden email] Subject: problem creating variables cross-referencing another member of a couple Hello people,
=====================
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
For a time series study on couples, we'd like to create new set of variables for each person corresponding to the "partner's score" on a set of variables. Couples were asked to make diary entries on their mood and other things, and we'd like to have a variable for the person's mood and then their partner's mood at the equivalent time, for example. We have a variable for each person's entry (1-60 entries), their couple (1-4 couples), and another variable just specifying whether they are member 1 or member 2 in that couple (a variable called 'member'). Then we have a set of 51 variables we'd like to examine. I've pasted in the syntax and then the error message below. Any help / ideas would be much appreciated! Many Thanks, Russell Deighton The syntax: vector v = happy TO both_unhelpaction. vector newvar(51). SORT CASES BY couple entry member (A). LOOP #n = 1 to 51. IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). END LOOP. EXECUTE. The error message: >Error # 4030 in column 23. Text: newvar >The operand appearing on the left side of the assignment operator (equals >sign) is not a known vector name or function name. >Execution of this command stops. IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). >Error # 4030 in column 51. Text: newvar >The operand appearing on the left side of the assignment operator (equals >sign) is not a known vector name or function name. >Execution of this command stops. END LOOP. EXECUTE. -- Sent from: http://spssx-discussion.1045642.n5.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 |
Administrator
|
In reply to this post by Jon Peck
Combining Jon's approach (slightly modified) with my own 'marriage'.
Note I use python simply to build the necessary rename list but leave the heavy lifting to the macro. I can't stand seeing stacks of spss.Submit when a simple macro call will do. -- DEFINE !PairData (ByVars !CHAREND ("/") /FlipVar !CHAREND ("/")/PairVars !CMDEND ) SORT CASES BY !ByVars (A). DATASET NAME raw. DATASET COPY copy. DATASET ACTIVATE copy. RECODE !FlipVar (1=2)(2=1). RENAME VARIABLES (!PairVars). SORT CASES BY !ByVars. MATCH FILES FILE raw / FILE * / BY !ByVars. !ENDDEFINE. BEGIN PROGRAM. def PairData (ByVars, FlipVar,PairFirst,PairLast): import spssaux newlist = " ".join([item + "_new" for item in spssaux.VariableDict().expand([PairFirst, "TO", PairLast])]) spss.Submit ('!PairData ' + 'ByVars=' + ByVars + "/FlipVar=" + FlipVar + "/PairVars="+ PairFirst + " TO " + PairLast + "=" + newlist ) END PROGRAM. NEW FILE. DATASET CLOSE ALL. OUTPUT CLOSE ALL. DATA LIST FREE /couple entry member happy x both . BEGIN DATA 1 1 1 2 3 4 1 1 2 5 6 7 1 2 1 1 3 7 1 2 2 6 1 4 2 1 1 2 8 7 2 1 2 3 6 8 2 2 1 1 3 6 2 2 2 2 1 4 END DATA. SET MPRINT ON PRINTBACK ON. BEGIN PROGRAM. PairData (ByVars='couple entry member',FlipVar='member', PairFirst='happy',PairLast='both') END PROGRAM. FORMATS ALL (F1.0). LIST. couple entry member happy x both happy_new x_new both_new 1 1 1 2 3 4 5 6 7 1 1 2 5 6 7 2 3 4 1 2 1 1 3 7 6 1 4 1 2 2 6 1 4 1 3 7 2 1 1 2 8 7 3 6 8 2 1 2 3 6 8 2 8 7 2 2 1 1 3 6 2 1 4 2 2 2 2 1 4 1 3 6 Number of cases read: 8 Number of cases listed: 8 Jon Peck wrote > Here's a slightly more ideomatic and perhaps more readable version of the > Python code. Functionality is the same. > > begin program. > import spssaux > > oldlist = spssaux.VariableDict().expand(["happy", "TO", > "both_unhelpaction"]) > newlist = [item + "_new" for item in oldlist] > spss.Submit ('RENAME VARIABLES (%s = %s)' % (" ".join(oldlist), " > ".join(newlist))) > end program. > > On Mon, Oct 23, 2017 at 8:15 AM, David Marso < > david.marso@ > > wrote: > >> Thanks Bruce, >> How about a little refinement using python ;-) >> This just does the RENAME portion. >> Everything else as is. >> Probably more elegant solutions than my crude python hack. >> >> begin program. >> import spssaux >> v=spssaux.VariableDict() >> newlist='' >> oldlist='' >> for ex in v.expand(["happy","TO","both_unhelpaction"]) : >> newlist=newlist+ex+'_new ' >> oldlist=oldlist+ex+' ' >> spss.Submit ('RENAME VARIABLES (' + oldlist + '=' + newlist + ').') >> end program. >> >> >> Bruce Weaver wrote >> > Nice solution, David. >> > >> > >> > David Marso wrote >> >> Might actually be much easier (and reliable) to do a DATASET copy >> ,rename >> >> variables, recode member, sort and MATCH. >> >> again untested. >> >> >> >> SORT CASES BY couple entry member (A). >> >> DATASET NAME raw. >> >> DATASET COPY copy. >> >> DATASET ACTIVATE copy. >> >> RECODE member (1=2)(2=1). >> >> RENAME VARIABLES (happy TO both_unhelpaction=new01 TO new51). >> >> SORT CASES BY couple entry member. >> >> MATCH FILES FILE raw / FILE * / BY couple entry member. >> >> >> >> >> >> >> >> >> >> David Marso wrote >> >>> The VECTOR declarations must be placed AFTER the SORT CASES command. >> >>> I have no idea what this is supposed to do. >> >>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) >> newvar(#n)=(v(#n+1)). >> >>> Definitely NOT what you intend. >> >>> You might find it easier to do this using the MATRIX language. >> >>> UNTESTED: >> >>> >> >>> SORT CASES BY couple entry member (A). >> >>> MATRIX. >> >>> GET ids /FILE */VARIABLES couple entry member. >> >>> GET scores /FILE */VARIABLES happy TO both_unhelpaction. >> >>> COMPUTE newvars=MAKE(NROW (scores),NCOL (scores),0). >> >>> LOOP #=1 TO NROW (scores)-1. >> >>> DO IF ids(#,1:2)= ids(#+1,1:2). >> >>> COMPUTE newvars(#,:)=scores(#+1,:). >> >>> COMPUTE newvars(#+1,:)=scores(#,:). >> >>> END IF. >> >>> END LOOP. >> >>> SAVE {ids ,scores ,newvars} >> >>> /OUTFILE * >> >>> /VARIABLES couple entry member scores01 TO scores51 Othrscores01 >> TO >> >>> Othrscores51. >> >>> END MATRIX. >> >>> >> >>> RENAME VARIABLES (up to you here.......). >> >>> <Could use APPLY DICTIONARY for these... >> >>> VARIABLE LABELS... >> >>> VALUE LABELS... >> >>> >> >>> &lt;quote author=&quot;Russell Deighton&quot;> >> >>> Hello people, >> >>> >> >>> For a time series study on couples, we'd like to create new set of >> >>> variables for each person corresponding to the "partner's score" on a >> >>> set >> >>> of variables. >> >>> >> >>> Couples were asked to make diary entries on their mood and other >> things, >> >>> and we'd like to have a variable for the person's mood and then their >> >>> partner's mood at the equivalent time, for example. >> >>> >> >>> We have a variable for each person's entry (1-60 entries), their >> couple >> >>> (1-4 couples), and another variable just specifying whether they are >> >>> member >> >>> 1 or member 2 in that couple (a variable called 'member'). Then we >> have >> >>> a >> >>> set of 51 variables we'd like to examine. >> >>> >> >>> I've pasted in the syntax and then the error message below. Any help >> / >> >>> ideas would be much appreciated! >> >>> >> >>> Many Thanks, >> >>> Russell Deighton >> >>> >> >>> The syntax: >> >>> >> >>> vector v = happy TO both_unhelpaction. >> >>> vector newvar(51). >> >>> SORT CASES BY couple entry member (A). >> >>> LOOP #n = 1 to 51. >> >>> IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). >> >>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) >> newvar(#n)=(v(#n+1)). >> >>> END LOOP. >> >>> EXECUTE. >> >>> >> >>> The error message: >> >>> >> >>>>Error # 4030 in column 23. Text: newvar >> >>>>The operand appearing on the left side of the assignment operator >> (equals >> >>>>sign) is not a known vector name or function name. >> >>>>Execution of this command stops. >> >>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) >> newvar(#n)=(v(#n+1)). >> >>> >> >>>>Error # 4030 in column 51. Text: newvar >> >>>>The operand appearing on the left side of the assignment operator >> (equals >> >>>>sign) is not a known vector name or function name. >> >>>>Execution of this command stops. >> >>> END LOOP. >> >>> EXECUTE. >> >>> >> >>> ===================== >> >>> To manage your subscription to SPSSX-L, send a message to >> >>> LISTSERV@.UGA (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?" >> >>> -- >> >>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >> >>> >> >>> ===================== >> >>> To manage your subscription to SPSSX-L, send a message to >> >> >> >>> LISTSERV@.UGA >> >> >> >>> (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?" >> >> -- >> >> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >> >> >> >> ===================== >> >> To manage your subscription to SPSSX-L, send a message to >> > >> >> LISTSERV@.UGA >> > >> >> (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 >> > >> > >> > >> > >> > >> > ----- >> > -- >> > Bruce Weaver >> >> > bweaver@ >> >> > http://sites.google.com/a/lakeheadu.ca/bweaver/ >> > >> > "When all else fails, RTFM." >> > >> > NOTE: My Hotmail account is not monitored regularly. >> > To send me an e-mail, please use the address shown above. >> > >> > -- >> > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >> > >> > ===================== >> > To manage your subscription to SPSSX-L, send a message to >> >> > LISTSERV@.UGA >> >> > (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?" >> -- >> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to >> > LISTSERV@.UGA > (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 >> > > > > -- > Jon K Peck > jkpeck@ > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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?" -- Sent from: http://spssx-discussion.1045642.n5.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
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
|
Anticipating Jon's next post ;-).
BEGIN PROGRAM. def PairData (ByVars, FlipVar,PairFirst,PairLast): import spssaux spss.Submit ('!PairData ByVars=%s/FlipVar=%s /PairVars=%s TO %s = %s' %(ByVars,FlipVar,PairFirst,PairLast, " ".join([item + "_new" for item in spssaux.VariableDict().expand([PairFirst, "TO", PairLast])]))) END PROGRAM. David Marso wrote > Combining Jon's approach (slightly modified) with my own 'marriage'. > Note I use python simply to build the necessary rename list but leave the > heavy lifting to the macro. > I can't stand seeing stacks of spss.Submit when a simple macro call will > do. > -- > DEFINE !PairData (ByVars !CHAREND ("/") /FlipVar !CHAREND ("/")/PairVars > !CMDEND ) > SORT CASES BY !ByVars (A). > DATASET NAME raw. > DATASET COPY copy. > DATASET ACTIVATE copy. > RECODE !FlipVar (1=2)(2=1). > RENAME VARIABLES (!PairVars). > SORT CASES BY !ByVars. > MATCH FILES FILE raw / FILE * / BY !ByVars. > !ENDDEFINE. > > > BEGIN PROGRAM. > def PairData (ByVars, FlipVar,PairFirst,PairLast): > import spssaux > newlist = " ".join([item + "_new" for item in > spssaux.VariableDict().expand([PairFirst, "TO", PairLast])]) > spss.Submit ('!PairData ' + 'ByVars=' + ByVars + "/FlipVar=" + FlipVar + > "/PairVars="+ PairFirst + " TO " + PairLast + "=" + newlist ) > END PROGRAM. > > > NEW FILE. > DATASET CLOSE ALL. > OUTPUT CLOSE ALL. > DATA LIST FREE /couple entry member happy x both . > BEGIN DATA > 1 1 1 2 3 4 > 1 1 2 5 6 7 > 1 2 1 1 3 7 > 1 2 2 6 1 4 > 2 1 1 2 8 7 > 2 1 2 3 6 8 > 2 2 1 1 3 6 > 2 2 2 2 1 4 > END DATA. > > SET MPRINT ON PRINTBACK ON. > BEGIN PROGRAM. > PairData (ByVars='couple entry member',FlipVar='member', > PairFirst='happy',PairLast='both') > END PROGRAM. > FORMATS ALL (F1.0). > LIST. > > > > > couple entry member happy x both happy_new x_new both_new > > 1 1 1 2 3 4 5 6 7 > 1 1 2 5 6 7 2 3 4 > 1 2 1 1 3 7 6 1 4 > 1 2 2 6 1 4 1 3 7 > 2 1 1 2 8 7 3 6 8 > 2 1 2 3 6 8 2 8 7 > 2 2 1 1 3 6 2 1 4 > 2 2 2 2 1 4 1 3 6 > > > Number of cases read: 8 Number of cases listed: 8 > > > Jon Peck wrote >> Here's a slightly more ideomatic and perhaps more readable version of the >> Python code. Functionality is the same. >> >> begin program. >> import spssaux >> >> oldlist = spssaux.VariableDict().expand(["happy", "TO", >> "both_unhelpaction"]) >> newlist = [item + "_new" for item in oldlist] >> spss.Submit ('RENAME VARIABLES (%s = %s)' % (" ".join(oldlist), " >> ".join(newlist))) >> end program. >> >> On Mon, Oct 23, 2017 at 8:15 AM, David Marso < > >> david.marso@ > >> > wrote: >> >>> Thanks Bruce, >>> How about a little refinement using python ;-) >>> This just does the RENAME portion. >>> Everything else as is. >>> Probably more elegant solutions than my crude python hack. >>> >>> begin program. >>> import spssaux >>> v=spssaux.VariableDict() >>> newlist='' >>> oldlist='' >>> for ex in v.expand(["happy","TO","both_unhelpaction"]) : >>> newlist=newlist+ex+'_new ' >>> oldlist=oldlist+ex+' ' >>> spss.Submit ('RENAME VARIABLES (' + oldlist + '=' + newlist + ').') >>> end program. >>> >>> >>> Bruce Weaver wrote >>> > Nice solution, David. >>> > >>> > >>> > David Marso wrote >>> >> Might actually be much easier (and reliable) to do a DATASET copy >>> ,rename >>> >> variables, recode member, sort and MATCH. >>> >> again untested. >>> >> >>> >> SORT CASES BY couple entry member (A). >>> >> DATASET NAME raw. >>> >> DATASET COPY copy. >>> >> DATASET ACTIVATE copy. >>> >> RECODE member (1=2)(2=1). >>> >> RENAME VARIABLES (happy TO both_unhelpaction=new01 TO new51). >>> >> SORT CASES BY couple entry member. >>> >> MATCH FILES FILE raw / FILE * / BY couple entry member. >>> >> >>> >> >>> >> >>> >> >>> >> David Marso wrote >>> >>> The VECTOR declarations must be placed AFTER the SORT CASES command. >>> >>> I have no idea what this is supposed to do. >>> >>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) >>> newvar(#n)=(v(#n+1)). >>> >>> Definitely NOT what you intend. >>> >>> You might find it easier to do this using the MATRIX language. >>> >>> UNTESTED: >>> >>> >>> >>> SORT CASES BY couple entry member (A). >>> >>> MATRIX. >>> >>> GET ids /FILE */VARIABLES couple entry member. >>> >>> GET scores /FILE */VARIABLES happy TO both_unhelpaction. >>> >>> COMPUTE newvars=MAKE(NROW (scores),NCOL (scores),0). >>> >>> LOOP #=1 TO NROW (scores)-1. >>> >>> DO IF ids(#,1:2)= ids(#+1,1:2). >>> >>> COMPUTE newvars(#,:)=scores(#+1,:). >>> >>> COMPUTE newvars(#+1,:)=scores(#,:). >>> >>> END IF. >>> >>> END LOOP. >>> >>> SAVE {ids ,scores ,newvars} >>> >>> /OUTFILE * >>> >>> /VARIABLES couple entry member scores01 TO scores51 Othrscores01 >>> TO >>> >>> Othrscores51. >>> >>> END MATRIX. >>> >>> >>> >>> RENAME VARIABLES (up to you here.......). >>> >>> <Could use APPLY DICTIONARY for these... >>> >>> VARIABLE LABELS... >>> >>> VALUE LABELS... >>> >>> >>> >>> &lt;quote author=&quot;Russell Deighton&quot;> >>> >>> Hello people, >>> >>> >>> >>> For a time series study on couples, we'd like to create new set of >>> >>> variables for each person corresponding to the "partner's score" on >>> a >>> >>> set >>> >>> of variables. >>> >>> >>> >>> Couples were asked to make diary entries on their mood and other >>> things, >>> >>> and we'd like to have a variable for the person's mood and then >>> their >>> >>> partner's mood at the equivalent time, for example. >>> >>> >>> >>> We have a variable for each person's entry (1-60 entries), their >>> couple >>> >>> (1-4 couples), and another variable just specifying whether they are >>> >>> member >>> >>> 1 or member 2 in that couple (a variable called 'member'). Then we >>> have >>> >>> a >>> >>> set of 51 variables we'd like to examine. >>> >>> >>> >>> I've pasted in the syntax and then the error message below. Any help >>> / >>> >>> ideas would be much appreciated! >>> >>> >>> >>> Many Thanks, >>> >>> Russell Deighton >>> >>> >>> >>> The syntax: >>> >>> >>> >>> vector v = happy TO both_unhelpaction. >>> >>> vector newvar(51). >>> >>> SORT CASES BY couple entry member (A). >>> >>> LOOP #n = 1 to 51. >>> >>> IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). >>> >>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) >>> newvar(#n)=(v(#n+1)). >>> >>> END LOOP. >>> >>> EXECUTE. >>> >>> >>> >>> The error message: >>> >>> >>> >>>>Error # 4030 in column 23. Text: newvar >>> >>>>The operand appearing on the left side of the assignment operator >>> (equals >>> >>>>sign) is not a known vector name or function name. >>> >>>>Execution of this command stops. >>> >>> IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) >>> newvar(#n)=(v(#n+1)). >>> >>> >>> >>>>Error # 4030 in column 51. Text: newvar >>> >>>>The operand appearing on the left side of the assignment operator >>> (equals >>> >>>>sign) is not a known vector name or function name. >>> >>>>Execution of this command stops. >>> >>> END LOOP. >>> >>> EXECUTE. >>> >>> >>> >>> ===================== >>> >>> To manage your subscription to SPSSX-L, send a message to >>> >>> LISTSERV@.UGA (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?" >>> >>> -- >>> >>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >>> >>> >>> >>> ===================== >>> >>> To manage your subscription to SPSSX-L, send a message to >>> >> >>> >>> LISTSERV@.UGA >>> >> >>> >>> (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?" >>> >> -- >>> >> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >>> >> >>> >> ===================== >>> >> To manage your subscription to SPSSX-L, send a message to >>> > >>> >> LISTSERV@.UGA >>> > >>> >> (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 >>> > >>> > >>> > >>> > >>> > >>> > ----- >>> > -- >>> > Bruce Weaver >>> >>> > bweaver@ >>> >>> > http://sites.google.com/a/lakeheadu.ca/bweaver/ >>> > >>> > "When all else fails, RTFM." >>> > >>> > NOTE: My Hotmail account is not monitored regularly. >>> > To send me an e-mail, please use the address shown above. >>> > >>> > -- >>> > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >>> > >>> > ===================== >>> > To manage your subscription to SPSSX-L, send a message to >>> >>> > LISTSERV@.UGA >>> >>> > (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?" >>> -- >>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/ >>> >>> ===================== >>> To manage your subscription to SPSSX-L, send a message to >>> > >> LISTSERV@.UGA > >> (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 >>> >> >> >> >> -- >> Jon K Peck > >> jkpeck@ > >> >> ===================== >> To manage your subscription to SPSSX-L, send a message to > >> LISTSERV@.UGA > >> (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?" > -- > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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?" -- Sent from: http://spssx-discussion.1045642.n5.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
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
|
In reply to this post by Rich Ulrich
That makes sense (to have a single record/row per couple rather than have the
data duplicated). That can be achieved with: FORMATS member (F1.0). CASESTOVARS ID=couple entry /INDEX=member/GROUPBY=INDEX . OTOH: I did have fun rumbling with python. Rich Ulrich wrote > I would follow this straight-forward logic: > > 1. XSAVE after IF and after ELSE to write 2 files, a separate file for > each partner; > > 2. RENAME (during the save) the variables for partner 2 (or, for both); > > 3. Match the two files. - you see $SYSMIS if the other record was not > there. > > > -- > > Rich Ulrich > > ________________________________ > From: SPSSX(r) Discussion < > SPSSX-L@.UGA > > on behalf of R Deighton < > russdeigh@ > > > Sent: Monday, October 23, 2017 7:29:39 PM > To: > SPSSX-L@.UGA > Subject: problem creating variables cross-referencing another member of a > couple > > Hello people, > > For a time series study on couples, we'd like to create new set of > variables > for each person corresponding to the "partner's score" on a set of > variables. > > Couples were asked to make diary entries on their mood and other things, > and > we'd like to have a variable for the person's mood and then their > partner's > mood at the equivalent time, for example. > > We have a variable for each person's entry (1-60 entries), their couple > (1-4 > couples), and another variable just specifying whether they are member 1 > or > member 2 in that couple (a variable called 'member'). Then we have a set > of > 51 variables we'd like to examine. > > I've pasted in the syntax and then the error message below. Any help / > ideas > would be much appreciated! > > Many Thanks, > Russell Deighton > > The syntax: > > vector v = happy TO both_unhelpaction. > vector newvar(51). > SORT CASES BY couple entry member (A). > LOOP #n = 1 to 51. > IF entry = LAG(entry) newvar(#n)=LAG(v(#n)). > IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). > END LOOP. > EXECUTE. > > The error message: > >>Error # 4030 in column 23. Text: newvar >>The operand appearing on the left side of the assignment operator (equals >>sign) is not a known vector name or function name. >>Execution of this command stops. > IF (entry <> LAG(entry) OR MISSING(LAG(entry))=1) newvar(#n)=(v(#n+1)). > >>Error # 4030 in column 51. Text: newvar >>The operand appearing on the left side of the assignment operator (equals >>sign) is not a known vector name or function name. >>Execution of this command stops. > END LOOP. > EXECUTE. > > > > -- > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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 > LISTSERV@.UGA > (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?" -- Sent from: http://spssx-discussion.1045642.n5.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
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?" |
Many thanks people! That's such a great help! I was obviously way off track.
The python code was above my head, but I really appreciate the elegance of it. The data set is now as hope for, so I'm very grateful. Russell -- Sent from: http://spssx-discussion.1045642.n5.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 |
Administrator
|
Curious, which of the various solutions did you use?
What was the actual final form of the desired resulting data. It occurred that perhaps you really didn't need a douible copy of the data but merely to associate the two sets of couples data. BTW the python code was merely a means to facilitate the renaming of the second set of variables. Kind of icing on the cake. R Deighton wrote > Many thanks people! That's such a great help! I was obviously way off > track. > The python code was above my head, but I really appreciate the elegance of > it. The data set is now as hope for, so I'm very grateful. > Russell > > > > -- > Sent from: http://spssx-discussion.1045642.n5.nabble.com/ > > ===================== > To manage your subscription to SPSSX-L, send a message to > LISTSERV@.UGA > (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?" -- Sent from: http://spssx-discussion.1045642.n5.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
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?" |
I actually went for the simple pure SPSS syntax version: Sorting, recoding
(switching member values), then matching the files as I wasn't sure about using Python - sorry I didn't do justice to your expert code! I actually found I had to use another MATCH command to get all of the data from 'copy' dataset back into the 'raw' dataset, but that's probably due to my limited syntax knowledge. I think I get what you mean that it could have been stored more efficiently as one data block, but for the subsequent analysis I think it could be helpful for me to keep it as a double block. Many Thanks again! Much Respect. (I actually now have another issue, which I think I'll submit as a separate post). -- Sent from: http://spssx-discussion.1045642.n5.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 |
Free forum by Nabble | Edit this page |