At 02:51 PM 10/17/2013, SeanSweeney wrote:
>I have a dataset with 25 variables, temporal measures. I want to >difference variable pairs for all temporal combinations (e.g., T1 - >T2, T1-T3....T24-T25). Another approach (we all have our preferred tools and styles) is to unroll your dataset, so each temporal measure is in a separate record, and then compute, probably using a DO REPEAT loop and LAG functions. Here, I assume that the single variable is called Time, and there's another called Time# that counts from 1 to 25. This can easily be done with VARSTOCASES. (Code not tested): NUMERIC SinceBack1 TO SinceBack24 (F4). DO REPEAT DiffVal = SinceBack1 TO SinceBack24 LAGVal = 1 TO 24. . DO IF LAGVal LT #Time#. . COMPUTE DiffVal = Time - LAG(Time,LAGVal). . END IF. END REPEAT. The result gives all the differences preceding each time value, in that value's record. It may be more convenient than having all 300-odd variables in one record. ===================== 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
Got it. Thanks for all the help!
Cheers, Sean ________________________________________ From: David Marso [via SPSSX Discussion] [[hidden email]] Sent: Friday, October 18, 2013 2:19 PM To: Sweeney, Sean P. Subject: RE: Automatically genrate new variables Add two more !DO !DOEND blocks traversing a list B1 B2 B3 etc One on the !HEAD of the list, the second on the !TAIL of the list. Beyond that, I do offer consulting and training. ---- SeanSweeney wrote Hi David, Yes, I did screw around with the code...it's working now. I've been doing intra-band differencing to this point. What if I want to do inter-band differencing as well? Take, for example this simplified dataset: T1 T2 T3 B1 B1 B1 B2 B2 B2 B3 B3 B3 B4 B4 B4 B5 B5 B5 B6 B6 B6 The output I would seek is the following: T1_B1-T2_B1, T1_B1-T3_B1, T1_B1-T1_B2, T1_B1-T2_B2, T1_B1-T3_B2, T1_B1-T1_B3, T1_B1-T2_B3....T1_B1-T3_B6 I know you've probably grown weary with this but any suggestions on how I might modify the code? Thanks for all help. Cheers, Sean ________________________________________ From: David Marso [via SPSSX Discussion] [[hidden email]</user/SendEmail.jtp?type=node&node=5722623&i=0>] Sent: Friday, October 18, 2013 1:29 PM To: Sweeney, Sean P. Subject: Re: Automatically genrate new variables Here is how it works on a sample 10 variable data set. Hard to say what you are running since you don't post the exact macro (hopefully exactly what I posted) and the macro call. SET MPRINT ON PRINTBACK ON is useful for debugging macros. As far as I can tell the macro works perfectly and you have somehow screwed around with it. SET MPRINT ON PRINTBACK ON. MakeSubs 1 10 T B1 DIFF. 35 0 M> 36 0 M> . 37 0 M> COMPUTE T1_T2_B1_DIFF = T1_B1 - T2_B1. 38 0 M> COMPUTE T1_T3_B1_DIFF = T1_B1 - T3_B1. 39 0 M> COMPUTE T1_T4_B1_DIFF = T1_B1 - T4_B1. 40 0 M> COMPUTE T1_T5_B1_DIFF = T1_B1 - T5_B1. 41 0 M> COMPUTE T1_T6_B1_DIFF = T1_B1 - T6_B1. 42 0 M> COMPUTE T1_T7_B1_DIFF = T1_B1 - T7_B1. 43 0 M> COMPUTE T1_T8_B1_DIFF = T1_B1 - T8_B1. 44 0 M> COMPUTE T1_T9_B1_DIFF = T1_B1 - T9_B1. 45 0 M> COMPUTE T1_T10_B1_DIFF = T1_B1 - T10_B1. 46 0 M> COMPUTE T2_T3_B1_DIFF = T2_B1 - T3_B1. 47 0 M> COMPUTE T2_T4_B1_DIFF = T2_B1 - T4_B1. 48 0 M> COMPUTE T2_T5_B1_DIFF = T2_B1 - T5_B1. 49 0 M> COMPUTE T2_T6_B1_DIFF = T2_B1 - T6_B1. 50 0 M> COMPUTE T2_T7_B1_DIFF = T2_B1 - T7_B1. 51 0 M> COMPUTE T2_T8_B1_DIFF = T2_B1 - T8_B1. 52 0 M> COMPUTE T2_T9_B1_DIFF = T2_B1 - T9_B1. 53 0 M> COMPUTE T2_T10_B1_DIFF = T2_B1 - T10_B1. 54 0 M> COMPUTE T3_T4_B1_DIFF = T3_B1 - T4_B1. 55 0 M> COMPUTE T3_T5_B1_DIFF = T3_B1 - T5_B1. 56 0 M> COMPUTE T3_T6_B1_DIFF = T3_B1 - T6_B1. 57 0 M> COMPUTE T3_T7_B1_DIFF = T3_B1 - T7_B1. 58 0 M> COMPUTE T3_T8_B1_DIFF = T3_B1 - T8_B1. 59 0 M> COMPUTE T3_T9_B1_DIFF = T3_B1 - T9_B1. 60 0 M> COMPUTE T3_T10_B1_DIFF = T3_B1 - T10_B1. 61 0 M> COMPUTE T4_T5_B1_DIFF = T4_B1 - T5_B1. 62 0 M> COMPUTE T4_T6_B1_DIFF = T4_B1 - T6_B1. 63 0 M> COMPUTE T4_T7_B1_DIFF = T4_B1 - T7_B1. 64 0 M> COMPUTE T4_T8_B1_DIFF = T4_B1 - T8_B1. 65 0 M> COMPUTE T4_T9_B1_DIFF = T4_B1 - T9_B1. 66 0 M> COMPUTE T4_T10_B1_DIFF = T4_B1 - T10_B1. 67 0 M> COMPUTE T5_T6_B1_DIFF = T5_B1 - T6_B1. 68 0 M> COMPUTE T5_T7_B1_DIFF = T5_B1 - T7_B1. 69 0 M> COMPUTE T5_T8_B1_DIFF = T5_B1 - T8_B1. 70 0 M> COMPUTE T5_T9_B1_DIFF = T5_B1 - T9_B1. 71 0 M> COMPUTE T5_T10_B1_DIFF = T5_B1 - T10_B1. 72 0 M> COMPUTE T6_T7_B1_DIFF = T6_B1 - T7_B1. 73 0 M> COMPUTE T6_T8_B1_DIFF = T6_B1 - T8_B1. 74 0 M> COMPUTE T6_T9_B1_DIFF = T6_B1 - T9_B1. 75 0 M> COMPUTE T6_T10_B1_DIFF = T6_B1 - T10_B1. 76 0 M> COMPUTE T7_T8_B1_DIFF = T7_B1 - T8_B1. 77 0 M> COMPUTE T7_T9_B1_DIFF = T7_B1 - T9_B1. 78 0 M> COMPUTE T7_T10_B1_DIFF = T7_B1 - T10_B1. 79 0 M> COMPUTE T8_T9_B1_DIFF = T8_B1 - T9_B1. 80 0 M> COMPUTE T8_T10_B1_DIFF = T8_B1 - T10_B1. 81 0 M> COMPUTE T9_T10_B1_DIFF = T9_B1 - T10_B1. SeanSweeney wrote Hi David, I ran into 1 little glitch...normal! On the first pass the macro differences in this order: T1_B1-T2_B1, T1_B1-T3_B1....T1_B1-T25B1 (which is what I want) On the second pass it differences in this order: T2_B1-T2_B1, T2_B1-T3_B1 (so I get values of zero for the first operation of the second pass) What I'd like it to do for the second pass and after is the following: 2nd pass T2_B1-T3_B1, T2_B1-T4_B1...T2_B1-T25_B1 3rd pass T3_B1-T4_B1, T3_B1-T5_B1... so I need incremental increases in the 2nd loop also...any suggestions? 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?" ________________________________ If you reply to this email, your message will be added to the discussion below: http://spssx-discussion.1045642.n5.nabble.com/Automatically-genrate-new-variables-tp5722599p5722621.html To unsubscribe from Automatically genrate new variables, click here< NAML<http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> 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?" ________________________________ If you reply to this email, your message will be added to the discussion below: http://spssx-discussion.1045642.n5.nabble.com/Automatically-genrate-new-variables-tp5722599p5722623.html To unsubscribe from Automatically genrate new variables, click here< NAML<http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> |
Free forum by Nabble | Edit this page |