|
Hello,
I think this might be fairly straightforward but I very rarely use SPSS for this kind of data management so any help would be very much appreciated. I have two vectors, start99 and end99, and I want to subtract the values of the latter from the former and from this create a third vector duration99. I tried doing this by the COMPUTE command I'd use if I was working without vectors but it is not accepted and I keep getting errors. If anyone could let me know what piece of syntax they'd use for this, I'd be grateful Many thanks Anna |
|
Anna,
Look at both the Loop-end loop command structure and the Do repeat-end repeat command structure. Both can be used. Perhaps I am reading too much into your messabe but upon reflection, there is something odd in your question. You say you have two vectors. Can I assume that you are familiar with the vector command? I'm unsure of whether you are using 'vector' in a math/programming sense, e.g., x(i), i=1,n, or in a more casual sense. If the former, looking at the Loop command will set you right. If the latter, please explain 'vector'. Gene Maguin -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of annastella Sent: Tuesday, March 23, 2010 3:58 PM To: [hidden email] Subject: vector query Hello, I think this might be fairly straightforward but I very rarely use SPSS for this kind of data management so any help would be very much appreciated. I have two vectors, start99 and end99, and I want to subtract the values of the latter from the former and from this create a third vector duration99. I tried doing this by the COMPUTE command I'd use if I was working without vectors but it is not accepted and I keep getting errors. If anyone could let me know what piece of syntax they'd use for this, I'd be grateful Many thanks Anna ===================== 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 |
|
In reply to this post by annastella
Do you mean something like this:
vector start= start1 to start99. vector endr= end1 to end99. vector duration= duration1 to duration99. loop #j= 1 to 9. compute duration(#j)=end(#j) - start(#j). end loop. desc var=duration1 to duration99. -Mike Palij New York University [hidden email] ----- Original Message ----- From: "annastella" <[hidden email]> To: <[hidden email]> Sent: Tuesday, March 23, 2010 3:58 PM Subject: vector query > Hello, > > I think this might be fairly straightforward but I very rarely use SPSS for > this kind of data management so any help would be very much appreciated. > > I have two vectors, start99 and end99, and I want to subtract the values of > the latter from the former and from this create a third vector duration99. > > I tried doing this by the COMPUTE command I'd use if I was working without > vectors but it is not accepted and I keep getting errors. > > If anyone could let me know what piece of syntax they'd use for this, I'd be > grateful > Many thanks > > Anna > > -- > View this message in context: http://old.nabble.com/vector-query-tp28006256p28006256.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 ===================== 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 |
|
In reply to this post by Maguin, Eugene
Thank you both for your replies. I managed that previous one but am now stuck with a new piece of syntax that does not seem to work.
VECTOR social(99). EXECUTE. VECTOR vsocial = social1 TO social99. EXECUTE. VECTOR vprim = primepisode1 TO primepisode99. VECTOR vstart= evst1 to evst99. VECTOR vend= evnd1 to evnd99. VECTOR voutput = social1 TO social99. LOOP #i=1 to 99. DO IF vprim(#i) =3 AND vstart (#i) < 25. COMPUTE voutput (#i) = 1. DO IF vprim (#i) =3 AND vstart (#i) > 97. COMPUTE voutput(#i) = 1. DO IF Vprim (#i)=3 AND vend (#i) < 25. COMPUTE voutput(#i) = 1. DO IF vprim (#i)=3 AND vend (#i) > 97. COMPUTE voutput(#i) = 1. ELSE. compute voutput(#i) = 0. END IF. END LOOP. EXECUTE. When I run it I keep getting these errors: Error # 4045. Command name: END LOOP The END LOOP command does not follow an unclosed LOOP command. Maybe the LOOP command was not recognized because of an error. Use the level-of-control shown to the left of the SPSS commands to determine the range of LOOPs and DO IFs. This command not executed. EXECUTE. Warning # 142. Command name: EXECUTE LOOP has no effect on this command. Error # 4095. Command name: EXECUTE The transformations program contains an unclosed LOOP, DO IF, or complex file structure. Use the level-of-control shown to the left of the SPSS commands to determine the range of LOOPs and DO IFs. This command not executed. Any insight on this would be much appreciated. Again, apologies for the basic query, am an absolute beginner with this SPSS part.. Thanks a lot in advance Anna
|
|
Annastella,
The error message is understandable--if you know what to look for. The specific problem is that each Do if needs to have its own End if. You have four Do ifs and only one End if. It might be that the second, third and fourth Do ifs should be Else ifs. Look at the Do if-End if command in the syntax reference. Gene Maguin >>Thank you both for your replies. I managed that previous one but am now stuck with a new piece of syntax that does not seem to work. VECTOR social(99). EXECUTE. VECTOR vsocial = social1 TO social99. EXECUTE. VECTOR vprim = primepisode1 TO primepisode99. VECTOR vstart= evst1 to evst99. VECTOR vend= evnd1 to evnd99. VECTOR voutput = social1 TO social99. LOOP #i=1 to 99. DO IF vprim(#i) =3 AND vstart (#i) < 25. COMPUTE voutput (#i) = 1. DO IF vprim (#i) =3 AND vstart (#i) > 97. COMPUTE voutput(#i) = 1. DO IF Vprim (#i)=3 AND vend (#i) < 25. COMPUTE voutput(#i) = 1. DO IF vprim (#i)=3 AND vend (#i) > 97. COMPUTE voutput(#i) = 1. ELSE. compute voutput(#i) = 0. END IF. END LOOP. EXECUTE. When I run it I keep getting these errors: Error # 4045. Command name: END LOOP The END LOOP command does not follow an unclosed LOOP command. Maybe the LOOP command was not recognized because of an error. Use the level-of-control shown to the left of the SPSS commands to determine the range of LOOPs and DO IFs. This command not executed. EXECUTE. Warning # 142. Command name: EXECUTE LOOP has no effect on this command. Error # 4095. Command name: EXECUTE The transformations program contains an unclosed LOOP, DO IF, or complex file structure. Use the level-of-control shown to the left of the SPSS commands to determine the range of LOOPs and DO IFs. This command not executed. Any insight on this would be much appreciated. Again, apologies for the basic query, am an absolute beginner with this SPSS part.. Thanks a lot in advance Anna Gene Maguin wrote: > > Anna, > > Look at both the Loop-end loop command structure and the Do repeat-end > repeat command structure. Both can be used. > > Perhaps I am reading too much into your messabe but upon reflection, there > is something odd in your question. You say you have two vectors. Can I > assume that you are familiar with the vector command? I'm unsure of > whether > you are using 'vector' in a math/programming sense, e.g., x(i), i=1,n, or > in > a more casual sense. If the former, looking at the Loop command will set > you > right. If the latter, please explain 'vector'. > > Gene Maguin > > > > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of > annastella > Sent: Tuesday, March 23, 2010 3:58 PM > To: [hidden email] > Subject: vector query > > Hello, > > I think this might be fairly straightforward but I very rarely use SPSS > for > this kind of data management so any help would be very much appreciated. > > I have two vectors, start99 and end99, and I want to subtract the values > of > the latter from the former and from this create a third vector duration99. > > I tried doing this by the COMPUTE command I'd use if I was working without > vectors but it is not accepted and I keep getting errors. > > If anyone could let me know what piece of syntax they'd use for this, I'd > be > grateful > Many thanks > > Anna > > ===================== > 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 > > -- View this message in context: http://old.nabble.com/vector-query-tp28006256p28288032.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 ===================== 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 |
|
In reply to this post by annastella
At 09:51 AM 4/21/2010, annastella wrote:
I now stuck with a piece of syntax that does not seem to work. OK, to start with, you have, VECTOR social(99). EXECUTE. VECTOR vsocial = social1 TO social99. EXECUTE. It doesn't seem to affect the code you've posted, but both those VECTOR commands will be lost. VECTOR statements only apply to the transformation program (or INPUT PROGRAM) in which they occur. EXECUTE terminates either kind of program (and forces SPSS to read the entire data file), so all you're getting is two wasted passes through the data. Sorry -- yes, you're hitting a hobby horse of mine. But EXECUTE is not harmless, and is not to be inserted without thinking why it's there, and what effect it will have. The large majority of posted EXECUTE statements are wasteful, in that they cause extra passes through the data, which can be a significant cost in large files, but they are otherwise harmless. Occasionally, however, an EXECUTE will 'break' code that would otherwise work, by trying to make two transformation programs from what are logically required to be only one. See "Use EXECUTE Sparingly" in any edition of Raynald Levesque's book(*). Then, you have (I'm adding indentation), VECTOR vprim = primepisode1 TO primepisode99. That's a simple, and natural, misunderstanding of how a DO IF construct is built. It you want only one of the COMPUTE statements executed, you probably want ELSE IF for all of the DO IFs except the first: VECTOR vprim = primepisode1 TO primepisode99. VECTOR vstart = evst1 to evst99. VECTOR vend = evnd1 to evnd99. VECTOR voutput = social1 TO social99. LOOP #i=1 to 99. . DO IF vprim(#i) =3 AND vstart (#i) < 25. . COMPUTE voutput (#i) = 1. . ELSE IF vprim (#i) =3 AND vstart (#i) > 97. . COMPUTE voutput(#i) = 1. . ELSE IF Vprim (#i) =3 AND vend (#i) < 25. . COMPUTE voutput(#i) = 1. . ELSE IF vprim (#i) =3 AND vend (#i) > 97. . COMPUTE voutput(#i) = 1. . ELSE. . compute voutput(#i) = 0. . END IF. END LOOP. You may, though, run into one of the quirks of DO IF: if any element of vprim is missing, or any element of vstart is missing, or any element of vend is missing and neither of the two vstart tests is satisfied, the corresponding element of voutput will not be assigned, and there will be no warning message. There are other ways to write this code, but I won't suggest any unless you have problems with this formulation. Good work, by the way, to be using a scratch variable (#i) as the loop index. That's very good practice, and is easy not to be aware of when you're new to SPSS. -Best wishes and best of luck to you, Richard ===================== 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 annastella
>VECTOR social(99).
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?" |
| Free forum by Nabble | Edit this page |
