|
I am trying to create a single "Start Month" variable (HStart) based upon a
series of monthly flag variables, the contents of which are all 1 or blank. I want the "Start Month" variable to capture the first non-blank month. I wrote the following syntax, but it didn't work, producing an error when I try to add "MISSING(HFY02M01 to HFY02M02)". Is there any way to specify that a range of variables are empty within a single logical statement? COMPUTE HStart=0. IF (HFY02M01=1) HStart=1. IF (MISSING(HFY02M01) AND (HFY02M02=1)) HStart=2. IF (MISSING(HFY02M01 to HFY02M02) AND (HFY02M03=1)) HStart=3. IF (MISSING(HFY02M01 to HFY02M03) AND (HFY02M04=1)) HStart=4. IF (MISSING(HFY02M01 to HFY02M04) AND (HFY02M05=1)) HStart=5. IF (MISSING(HFY02M01 to HFY02M05) AND (HFY02M06=1)) HStart=6. IF (MISSING(HFY02M01 to HFY02M06) AND (HFY02M07=1)) HStart=7. IF (MISSING(HFY02M01 to HFY02M07) AND (HFY02M08=1)) HStart=8. IF (MISSING(HFY02M01 to HFY02M08) AND (HFY02M09=1)) HStart=9. IF (MISSING(HFY02M01 to HFY02M09) AND (HFY02M10=1)) HStart=10. IF (MISSING(HFY02M01 to HFY02M10) AND (HFY02M11=1)) HStart=11. IF (MISSING(HFY02M01 to HFY02M11) AND (HFY02M12=1)) HStart=12. IF (MISSING(HFY02M01 to HFY09M12)) HStart=99. VARIABLE LABELS HStart 'Start Month in 2002 for ...'. EXECUTE. VALUE LABELS HStart 1 '2002 Jan' 2 '2002 Feb' 3 '2002 Mar' 4 '2002 Apr' 5 '2002 May' 6 '2002 Jun' 7 '2002 Jul' 8 '2002 Aug' 9 '2002 Sep' 10 '2002 Oct' 11 '2002 Nov' 12 '2002 Dec' 99 'No Months'. EXECUTE. ===================== 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
Patrick Burns, Senior Researcher
Economic Roundtable
315 W. 9th Street, Suite 502
Los Angeles, CA, 90015-4200
http://www.economicrt.org
|
|
MISSING takes only a single variable, but using a loop would be a lot less painful anyway. Try something like the following. (It assumes no missing values are declared, but it would be easy to adapt.) compute newval = 0. vector v = HFY02M01 to HFY02M12. loop #i = 1 to 12. do if v(#i) = 1. compute hstart = #i. break. end if. end loop. HTH, Jon Peck SPSS, an IBM Company [hidden email] 312-651-3435
I am trying to create a single "Start Month" variable (HStart) based upon a series of monthly flag variables, the contents of which are all 1 or blank. I want the "Start Month" variable to capture the first non-blank month. I wrote the following syntax, but it didn't work, producing an error when I try to add "MISSING(HFY02M01 to HFY02M02)". Is there any way to specify that a range of variables are empty within a single logical statement? COMPUTE HStart=0. IF (HFY02M01=1) HStart=1. IF (MISSING(HFY02M01) AND (HFY02M02=1)) HStart=2. IF (MISSING(HFY02M01 to HFY02M02) AND (HFY02M03=1)) HStart=3. IF (MISSING(HFY02M01 to HFY02M03) AND (HFY02M04=1)) HStart=4. IF (MISSING(HFY02M01 to HFY02M04) AND (HFY02M05=1)) HStart=5. IF (MISSING(HFY02M01 to HFY02M05) AND (HFY02M06=1)) HStart=6. IF (MISSING(HFY02M01 to HFY02M06) AND (HFY02M07=1)) HStart=7. IF (MISSING(HFY02M01 to HFY02M07) AND (HFY02M08=1)) HStart=8. IF (MISSING(HFY02M01 to HFY02M08) AND (HFY02M09=1)) HStart=9. IF (MISSING(HFY02M01 to HFY02M09) AND (HFY02M10=1)) HStart=10. IF (MISSING(HFY02M01 to HFY02M10) AND (HFY02M11=1)) HStart=11. IF (MISSING(HFY02M01 to HFY02M11) AND (HFY02M12=1)) HStart=12. IF (MISSING(HFY02M01 to HFY09M12)) HStart=99. VARIABLE LABELS HStart 'Start Month in 2002 for ...'. EXECUTE. VALUE LABELS HStart 1 '2002 Jan' 2 '2002 Feb' 3 '2002 Mar' 4 '2002 Apr' 5 '2002 May' 6 '2002 Jun' 7 '2002 Jul' 8 '2002 Aug' 9 '2002 Sep' 10 '2002 Oct' 11 '2002 Nov' 12 '2002 Dec' 99 'No Months'. EXECUTE. ===================== 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 Patrick Burns
Patrick,
Check out the NVALID function which returns a count of the arguments that have valid, nonmissing values. This function requires one or more arguments, which should be variable names in the active dataset. e.g., IF (NVALID(HFY02M01 to HFY02M02)=0 AND (HFY02M03=1)) HStart=3. IF (NVALID(HFY02M01 to HFY02M03)=0 AND (HFY02M04=1)) HStart=4. Florio At 08:50 PM 2/22/2010, Patrick Burns wrote: >I am trying to create a single "Start Month" variable (HStart) based upon a >series of monthly flag variables, the contents of which are all 1 or blank. > I want the "Start Month" variable to capture the first non-blank month. > >I wrote the following syntax, but it didn't work, producing an error when I >try to add "MISSING(HFY02M01 to HFY02M02)". Is there any way to specify >that a range of variables are empty within a single logical statement? > >COMPUTE HStart=0. >IF (HFY02M01=1) HStart=1. >IF (MISSING(HFY02M01) AND (HFY02M02=1)) HStart=2. >IF (MISSING(HFY02M01 to HFY02M02) AND (HFY02M03=1)) HStart=3. >IF (MISSING(HFY02M01 to HFY02M03) AND (HFY02M04=1)) HStart=4. >IF (MISSING(HFY02M01 to HFY02M04) AND (HFY02M05=1)) HStart=5. >IF (MISSING(HFY02M01 to HFY02M05) AND (HFY02M06=1)) HStart=6. >IF (MISSING(HFY02M01 to HFY02M06) AND (HFY02M07=1)) HStart=7. >IF (MISSING(HFY02M01 to HFY02M07) AND (HFY02M08=1)) HStart=8. >IF (MISSING(HFY02M01 to HFY02M08) AND (HFY02M09=1)) HStart=9. >IF (MISSING(HFY02M01 to HFY02M09) AND (HFY02M10=1)) HStart=10. >IF (MISSING(HFY02M01 to HFY02M10) AND (HFY02M11=1)) HStart=11. >IF (MISSING(HFY02M01 to HFY02M11) AND (HFY02M12=1)) HStart=12. >IF (MISSING(HFY02M01 to HFY09M12)) HStart=99. >VARIABLE LABELS HStart 'Start Month in 2002 for ...'. >EXECUTE. > >VALUE LABELS HStart >1 '2002 Jan' >2 '2002 Feb' >3 '2002 Mar' >4 '2002 Apr' >5 '2002 May' >6 '2002 Jun' >7 '2002 Jul' >8 '2002 Aug' >9 '2002 Sep' >10 '2002 Oct' >11 '2002 Nov' >12 '2002 Dec' >99 'No Months'. >EXECUTE. > >===================== >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 |
| Free forum by Nabble | Edit this page |
