Date: Sat, 3 Feb 2007 08:23:22 -0600 "Peck, Jon" "SPSSX(r) Discussion" "Peck, Jon" Re: Recoding A<453599.39052.qm@web32711.mail.mud.yahoo.com> text/plain; charset="utf-8"

Note that using the ANY function will greatly simplify the test criteria in example 3. Change do if ((yage15=par1)|(yage15=par2)|(yage15=par3)|(yage15=par4)|(yage15=par5)|(yage15=par6)|(yage15=par7)|(yage15=par8)).

into do if any(ya15, par1 to par8).

HTH, Jon Peck

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Albert-jan Roskam Sent: Saturday, February 03, 2007 4:39 AM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: [SPSSX-L] Recoding

Hi Wayne,

Example 1 (untested!): VECTOR age(49). /* creation of 49 empty age vars. VECTOR v_age=age1 TO age49. /* definition of vector/array 'v_age'. LOOP #I=1 TO 49. + IF (age = #I) v_age(#I) = 1. + IF (age ne #I) v_age(#I) = 0. END LOOP. EXE.

--> as you mentioned already, a macro loop would also be an option. Are you sure you want all values not being #i to be recoded to 0 -- INCLUDING MISSING VALUES? If so, you could make it easier just by replacing the IF rules with: COUNT v_age(#I) = age (#I).

If not, just add a rule that retains the original missing values (user and/or system missing values).

Cheers! Albert-Jan

--- Chen Wei <weichen@ruc.edu.cn> wrote:

> Hi, > > I am a biginner in using SPSS, I am creating dummy > variables and recoding some categorical variables. > These are easy to do with the following syntax, but > I will need to repeat 35 times doing the same thing. > Could anyone sugest how to use Vector and Loop > Structure or Macro to do the job? Thanks very much. > > Wayne > > ************************** > *Example 1 > > if(age=15)age15=1. > if(age~=15)age15=0. > > if(age=16)age16=1. > if(age~=16)age16=0. > ...... > if(age=49)age49=1. > if(age~=49)age49=0. > ************************** > *Example 2 > > do if yage15<2000. > recode marry15 to marry49 (0=1). > end if. > execute. > > do if yage16<2000. > recode marry16 to marry49 (0=1). > end if. > execute. > ...... > do if yage49<2000. > recode marry49 (0=1). > end if. > execute. > ************************** > *Example 3 > > do if > ((yage15=par1)|(yage15=par2)|(yage15=par3)|(yage15=par4)|(yage15=par5)|(yage15=par6)|(yage15=par7)|(yage15=par8)). > recode child15 (0=1). > end if. > execute. > > do if > ((yage16=par1)|(yage16=par2)|(yage16=par3)|(yage16=par4)|(yage16=par5)|(yage16=par6)|(yage16=par7)|(yage16=par8)). > recode child16 (0=1). > end if. > execute. > ...... > do if > ((yage49=par1)|(yage49=par2)|(yage49=par3)|(yage49=par4)|(yage49=par5)|(yage49=par6)|(yage49=par7)|(yage49=par8)). > recode child49 (0=1). > end if. > execute. > *************************** >

____________________________________________________________________________________ No need to miss a message. Get email on-the-go with Yahoo! Mail for Mobile. Get started. http://mobile.yahoo.com/mail

Back to: Top of message | Previous page | Main SPSSX-L page