Hi,
I am having difficulty troubleshooting the best way to run a series of IF commands. Perhaps there is even an easier set of syntax to use I have about 20 variables that have 1 of 120 colleges listed. I want to calculate a flag if a specific college is found across the case -- some cases may have more than one college or a college listed Here is where I'm at, I think someone with experience DO REPEAT C = Type1 TO Type119. COMPUTE C=$SYSMIS. DO REPEAT D = 1 TO 119. IF (ANY(D, College.1,rCollege.2,rCollege.3,rCollege.4,rCollege.5,rCollege.6,rCollege.7,rCollege.8, rCollege.9,rCollege.10,rCollege.11,rCollege.12,rCollege.13,rCollege.14,rCollege.15,rCollege.16, rCollege.17,rCollege.18,rCollege.19)) C=1. END REPEAT. END REPEAT. EXECUTE. I know the worst-case scenario is that I do this a bunch of times manually: IF (ANY(1, rCollege.1,rCollege.2,rCollege.3,rCollege.4,rCollege.5,rCollege.6,rCollege.7,rCollege.8, rCollege.9,rCollege.10,rCollege.11,rCollege.12,rCollege.13,rCollege.14,rCollege.15,rCollege.16, rCollege.17,rCollege.18,rCollege.19)) Type1=1. EXECUTE. IF (ANY(2, rCollege.1,rCollege.2,rCollege.3,rCollege.4,rCollege.5,rCollege.6,rCollege.7,rCollege.8, rCollege.9,rCollege.10,rCollege.11,rCollege.12,rCollege.13,rCollege.14,rCollege.15,rCollege.16, rCollege.17,rCollege.18,rCollege.19)) Type2=1. EXECUTE. IF (ANY(3, rCollege.1,rCollege.2,rCollege.3,rCollege.4,rCollege.5,rCollege.6,rCollege.7,rCollege.8, rCollege.9,rCollege.10,rCollege.11,rCollege.12,rCollege.13,rCollege.14,rCollege.15,rCollege.16, rCollege.17,rCollege.18,rCollege.19)) Type3=1. EXECUTE. IF (ANY(4, rCollege.1,rCollege.2,rCollege.3,rCollege.4,rCollege.5,rCollege.6,rCollege.7,rCollege.8, rCollege.9,rCollege.10,rCollege.11,rCollege.12,rCollege.13,rCollege.14,rCollege.15,rCollege.16, rCollege.17,rCollege.18,rCollege.19)) EXECUTE. IF (ANY(5, rCollege.1,rCollege.2,rCollege.3,rCollege.4,rCollege.5,rCollege.6,rCollege.7,rCollege.8, rCollege.9,rCollege.10,rCollege.11,rCollege.12,rCollege.13,rCollege.14,rCollege.15,rCollege.16, rCollege.17,rCollege.18,rCollege.19)) EXECUTE. Please help me troubleshoot, I have studied the help files without success. Thank you, in advance!! Thank you, Jason Jason Vander Weele | Institutional Research and Planning Analyst Lakeshore Technical College 1290 North Avenue | Cleveland, WI 53015 Phone: (920) 693-1288 | Email: [hidden email] Changing Lives. Building Futures. |
David or Bruce may well have a better, more compact, method but it seems that you want to do this:
DO REPEAT C = Type1 TO Type119/D = 1 TO 119. Basically, you want to see if any variables in the list college.1 to rcollege.19 have value of 1 and, if so, set type1 to 1. And then repeat for D =2 and on.
So you march through the two lists (C and D) in parallel. Just out of curiosity, should ‘college.1’ by ‘rcollege.1’?
Gene Maguin From: SPSSX(r) Discussion [mailto:[hidden email]]
On Behalf Of Jason Vander Weele Hi, than the one I am trying here with the DO REPEAT. across multiple variables. in this might be able to see what I'm trying to do. I know the syntax isn't correct because it is not working. Type4=1. Type5=1. EXECUTE. Please help me troubleshoot, I have studied the help files without success. Thank you, in advance!!
|
In reply to this post by Jason Vander Weele
You don't need nested DO REPEATS, you can specify multiple lists on one DO REPEAT. The below (untested) code first makes the vector of 119 Type flags, and then tests against the 19 College.?? fields. This also presumes the College.?? fields are contiguous in the dataset, if not you will need to write them all out as you have already done (or sort the variables beforehand so they are contiguous).
**********************. VECTOR Type(119,F1.0). DO REPEAT C = Type1 TO Type119 /D = 1 TO 119. IF (ANY(D,College.1 TO College.19)) C=1. END REPEAT. **********************. |
Administrator
|
In reply to this post by Jason Vander Weele
DO REPEATS cannot be nested.
You want to learn about VECTOR and LOOP. NUMERIC Type001 TO Type119 . VECTOR Type=Type001 TO Type119. LOOP #=1 TO 119. + COMPUTE TYPE(#)= ANY(#, College.1 TO College.19 ) . END LOOP. /** EXECUTE **/. * This belies my own coding preference to *. 1. have variables contain the same number of digit characters. 2. Use Booleans (0,1) rather than have SYSMIS in the data. 3. Use TO whenever possible. 4. Pass data only when necessary (hence commented EXECUTE). If you don't care about the same digit thing then this could also be written as. VECTOR type(119). LOOP #=1 TO 119. + COMPUTE TYPE(#)= ANY(#, College.1 TO College.19 ) . END LOOP. or use DO REPEAT but index into the vector. ----- HTH... -----
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 Jason Vander Weele
At 03:20 PM 2/18/2014, Jason Vander Weele wrote:
>I have about 20 variables that have 1 of 120 colleges listed. I want >to calculate a flag if a specific college is found across the case -- And you want to do that for all 119 colleges (as you say below), so you'll have 119 flag variables. That's a clumsy structure; think how you're going to use it, and maybe ask on this list, to see if some other structure would serve your purpose better. In the meantime, here's what you posted, which I've reformatted: >DO REPEAT C = Type1 TO Type119. >. COMPUTE C=$SYSMIS. >. DO REPEAT D = 1 TO 119. >. IF (ANY(D, > College.1, rCollege.2, rCollege.3, rCollege.4, rCollege.5, > rCollege.6, rCollege.7, rCollege.8, rCollege.9, rCollege.10, > rCollege.11,rCollege.12,rCollege.13,rCollege.14,rCollege.15, > rCollege.16,rCollege.17,rCollege.18,rCollege.19)) C=1. >. END REPEAT. >END REPEAT. >EXECUTE. Your problem is you're looping through the 119 indicator variables and the 119 indicator values separately, rather than together. It'll set each indicator variable if ANY of the 119 colleges appears in the list of 19. Here's the smallest adjustment to your code that should work. (I've taken out "COMPUTE C=$SYSMIS" and "EXECUTE", neither of which you need. Really. "EXECUTE" is rarely needed.) DO REPEAT C = Type1 TO Type119. /D = 1 TO 119. . IF (ANY(D, College.1, rCollege.2, rCollege.3, rCollege.4, rCollege.5, rCollege.6, rCollege.7, rCollege.8, rCollege.9, rCollege.10, rCollege.11,rCollege.12,rCollege.13,rCollege.14,rCollege.15, rCollege.16,rCollege.17,rCollege.18,rCollege.19)) C=1. . END REPEAT. END REPEAT. Notice that there's now one DO REPEAT construct with two stand-in variables, C and D, rather than two DO REPEAT constructs, one nested within the other. ===================== 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 David Marso
At 03:56 PM 2/18/2014, David Marso wrote:
>DO REPEATS cannot be nested. Sure they can. It's just not what the poster needs to get the effect he wants. ===================== 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 David Marso
Here's the DO REPEAT that David does not show. It would be my usual approach. VECTOR type(119). /* initialize to 0 or SYSMIS as preferred*/. RECODE type1 to type119(ELSE=SYSMIS). DO REPEAT coll= College.1 TO College.19 . + IF ( (coll GE 1) AND (coll LE 119) TYPE(coll)= 1. END REPEAT. -- Rich Ulrich > Date: Tue, 18 Feb 2014 12:56:01 -0800 <div onmouseout="SkypeClick2Call.MenuInjectionHandler.hideMenu(event)" onmouseover="SkypeClick2Call.MenuInjectionHandler.showMenu(this, event)" style="display: none;" id="skype_c2c_menu_container" class="skype_c2c_menu_container">> From: [hidden email] > Subject: Re: Do Repeat Ifs > To: [hidden email] > > DO REPEATS cannot be nested. > You want to learn about VECTOR and LOOP. > > NUMERIC Type001 TO Type119 . > VECTOR Type=Type001 TO Type119. > LOOP #=1 TO 119. > + COMPUTE TYPE(#)= ANY(#, College.1 TO College.19 ) . > END LOOP. > /** EXECUTE **/. > > * This belies my own coding preference to *. > 1. have variables contain the same number of digit characters. > 2. Use Booleans (0,1) rather than have SYSMIS in the data. > 3. Use TO whenever possible. > 4. Pass data only when necessary (hence commented EXECUTE). > > If you don't care about the same digit thing then this could also be written > as. > VECTOR type(119). > LOOP #=1 TO 119. > + COMPUTE TYPE(#)= ANY(#, College.1 TO College.19 ) . > END LOOP. > > or use DO REPEAT but index into the vector. > ----- > HTH... You'll need Skype CreditFree via Skype |
In reply to this post by Richard Ristow
Thank you everyone, seeing your solutions has helped me better understand these commands and how to work with them. I have been able to use your solutions and solve my problem, thank you!
I also appreciate the suggestions for improving my syntax, each day I learn something new.
In summary, the variables are a time series of which schools a person was enrolled (hence a student may have the same school semester after semester), with another variable indicating the specific dates of the enrollment. While this dataset isn't structured very well for doing statistical analysis, the purpose for now, anyway, is to get a count of each school name attended - to see simply the names of schools students have attended without duplicating the count.
At a later date I might try to connect with anyone who's worked with National Student Clearinghouse data to get a better grasp on how they've manipulated those datasets to study students over time. Unfortunately the clock is ticking for this time.
Thanks again for all the help! Thank you, Jason Jason Vander Weele | Institutional Research and Planning Analyst 1290 North Avenue | Cleveland, WI 53015 Phone: (920) 693-1288 | Email: [hidden email] Changing Lives. Building Futures. On Tue, Feb 18, 2014 at 3:16 PM, Richard Ristow <[hidden email]> wrote:
|
In reply to this post by Jason Vander Weele
At 03:56 PM 2/18/2014, David Marso wrote:
>DO REPEATS cannot be nested. Sure they can. It's just not what the poster needs to get the effect he wants. Here's actually a fairly natural way to solve the original problem with nested DO REPEATs: DO REPEAT C = Type1 TO Type119. /D = 1 TO 119. . DO REPEAT College= College.1 TO rCollege.19. . IF College EQ D C =1. . END REPEAT. END REPEAT. (And my previous solution left in the extra END REPEAT) ===================== 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 Richard Ristow
LOOPs can be nested. DO REPEAT not.
I can't think of where it be useful anyway (without a vector).. eg. DO REPEAT X=x1 TO x10. DO REPEAT Y=Y1 TO Y10. COMPUTE X=UNIFORM(1). COMPUTE Y=UNIFORM(1). END REPEAT. END REPEAT. >Error # 4530. Command name: DO REPEAT >This command is not allowed inside the DO REPEAT/ END REPEAT facility. The >command will be ignored. >Execution of this command stops.
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
I like that approach of looping only through 19 colleges rather than the 119 values.
OTOH, I have a preference for LOOP over DO REPEAT (also for same # digits in variables sets). Think of INDEX in VARSTOCASES as one example of why the latter might be the case. NUMERIC type001 TO type119 . RECODE type001 TO type119 (ELSE=0). VECTOR coll = college.1 TO college.19 / type = type001 TO type119 . LOOP #=1 TO 19. IF RANGE(coll(#),1,119) type(coll(#))=1. END LOOP.
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 |