|
Hello,
I have a series of variables epis1 to epis99 with values from 0-5, they refer to episodes in sequence. I am trying to calculate the times when a value of 5 is interrupted by a value of 2 for each case, as well as the times when a value of 5 is interrupted by a value of 2 and then followed by a 5 again. I am not entirely sure about the commands I can use to do that, any ideas would be very much appreciated. Best Anna |
|
Administrator
|
If you mean you are trying to flag occurrences of the sequences '52' and '525', then you could do it with vectors and a loop, like this:
new file. dataset close all. * Create some sample data . data list list / epis1 to epis9 (9f1.0). begin data 1 2 3 4 5 2 5 3 4 3 5 2 3 4 5 3 2 1 1 3 5 4 3 1 3 2 5 end data. numeric seq52.1 to seq52.9 seq525.1 to seq525.9 (f1.0) . * Initialize to 0. recode seq52.1 to seq52.9 seq525.1 to seq525.9 (else=0). exe. vector e = epis1 to epis9 / s52 = seq52.1 to seq52.9 / s525 = seq525.1 to seq525.9 . loop #i = 2 to 9. - compute s52(#i) = e(#i) EQ 2 and e(#i-1) EQ 5. - if (#i GT 2) s525(#i) = e(#i) EQ 5 and e(#i-1) EQ 2 and e(#i-2) EQ 5 . end loop. exe. Is this giving what you want?
--
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/). |
|
In reply to this post by annastella
Anna,
It would be really helpful to all if you'd provide example data. Thus far it seems like you have two cases. You need to define 'interrupted'. With respect, your usage is nonstandard US english. I guess at what it means but I could easily be wrong. You have 99 variables. For the example, let's say you have 10 variables. I'll assume they are in a wide format file. Case 1. '... when a value of 5 is interrupted by a value of 2 for each case, ...' Case 2. '... when a value of 5 is interrupted by a value of 2 and then followed by a 5 again.' 1 0 4 5 2 2 2 2 2 2 case 1 example 0 0 0 0 0 5 5 3 5 2 case 1 example 1 3 4 5 2 5 4 3 0 0 case 2 example 0 0 0 5 2 2 2 2 2 5 case 2 example 5 2 3 5 5 5 5 0 2 2 Neither a case 1 or case 2 example 0 5 2 4 5 2 5 5 2 2 Both case 1 and case 2. Does it count for both? Depending on the meaning of 'interrupted', these examples may be all wrong. Even if I have guessed the meaning correctly, I may have not clearly defined 'case 1', 'case 2' and 'not case 1 and not case 2'. Defining the cases and 'not' cases via examples is the first task and it's your task. All that said, I think there may be two ways of attacking the problem. One definite way is to use Vectors and Loops (if you aren't familiar with these commands, you might as well start reading up on them now because you will be very soon) and the other way may be to 'unroll' the file via a varstocases command (look at that command also). Gene Maguin >>I have a series of variables epis1 to epis99 with values from 0-5, they refer to episodes in sequence. I am trying to calculate the times when a value of 5 is interrupted by a value of 2 for each case, as well as the times when a value of 5 is interrupted by a value of 2 and then followed by a 5 again. I am not entirely sure about the commands I can use to do that, any ideas would be very much appreciated. Best 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
At 03:20 PM 7/12/2010, annastella wrote:
I have a series of variables epis1 to epis99 with values from 0-5, they refer to episodes in sequence. I am trying to calculate the times when a value of 5 is interrupted by a value of 2 for each case, as well as the times when a value of 5 is interrupted by a value of 2 and then followed by a 5 again. So you want to mark times when a 5 is followed by a 2; and when a 5 is followed by a 2 and then a 5? You use VECTOR and LOOP for that. Like this, but again I'm afraid this code is NOT TESTED. And it doesn't check for missing or invalid values in the input. VECTOR Code=epis1 TO epis99. VECTOR Chng(99,F2). VAL LABELS Chng1 TO Chng99 (1 = '2 after 5') (2 = '5 after 2-5)' (0 = 'Other'). RECODE Chng1 TO Chng99 (ELSE=0) /* Initialize to 0 */. LOOP #Episode = 2 TO 99. . IF Code(#Episode) EQ 2 AND Code(#Episode-1) EQ 5 Chng(#Episode)=1. . IF Code(#Episode) EQ 5 AND Chng(#Episode-1) EQ 1 Chng(#Episode)=2. END LOOP. Then you can use COUNT to count the occurrences of each type of change, or other logic to find when earliest and latest values occur, or whatever you choose. ===================== 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
If by "interrupted" you mean "followed" this is an interpretation fo
what you may mean. See if this simulation produces t what you want. * make up data that sounds like the post. new file. input program. vector epis (99,f1). loop id = 1 to 100. loop #e = 1 to 99. COMPUTE epis(#e)=RND(RV.UNIFORM(.5,6.5))-1. end loop. end case. end loop. end file. end input program. * is this the kind of tests you are looking for? . compute ntest1 = 0. compute ntest2 = 0. compute havetest1 =0. loop #test1 = 2 to 99. do if epis(#test1) eq 2 and epis(#test1-1) eq 5. compute ntest1 = ntest1 + 1. compute havetest1 =1. end if. do if havetest1 and epis(#test1) eq 5. compute ntest2 = ntest2+1. compute havetest1 =0. end if. end loop. crosstabs tables= ntest1 by ntest2. Art Kendall Social Research Consultants On 7/12/2010 3:20 PM, annastella wrote: > Hello, > > I have a series of variables epis1 to epis99 with values from 0-5, they > refer to episodes in sequence. I am trying to calculate the times when a > value of 5 is interrupted by a value of 2 for each case, as well as the > times when a value of 5 is interrupted by a value of 2 and then followed by > a 5 again. > I am not entirely sure about the commands I can use to do that, any ideas > would be very much appreciated. > > Best > Anna > -- > View this message in context: http://old.nabble.com/syntax-help-tp29139802p29139802.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
Art Kendall
Social Research Consultants |
| Free forum by Nabble | Edit this page |
