It looks like this is solved, but wanted to mention that
dichotomies can be easily calculated in a single compute statement as follows: compute age15 =(age=15). Generically: Compute newvar=(expression that would result in a yes). If the condition is met, then the value of newvar is 1. If the condition is not met, then the value of newvar is 0. If the values in the condition are missing then newvar is missing. Melissa The bubbling brook would lose its song if you removed the rocks. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bauer, John H. Sent: Friday, February 02, 2007 1:50 PM To: [hidden email] Subject: Re: [SPSSX-L] Recoding This is very easy to do if you have the Programmability Extension installed. Note that it is easier to use "Compute age16 = (age=16) ." instead of a pair of IF statements. I have left Example 3 as an exercise for the List. Read the article "Converting an SPSS Syntax Job to a Python Job" at http://www.spss.com/devcentral/index.cfm?pg=articleDet&artId=5 to get started; follow up with the Programming and Data Management book chapters 13 and 20: http://www.spss.com/spss/data_management_book.htm http://www.spss.com/spss/SPSSdatamgmt_4e.pdf It took me less time to write and test the code below than it did to write this e-mail :-), so I hope some of you will find the effort worthwhile. begin program python. import spss for age in xrange(16, 50): spss.Submit("compute age%(age)s = (age=%(age)s)." % locals()) spss.Submit("execute.") end program. begin program python. import spss cmds = """ do if yage%(age)s<2000. recode marry%(age)s to marry49 (0=1). end if. """ for age in xrange(16, 50): spss.Submit(cmds % locals()) spss.Submit("execute.") end program. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Chen Wei Sent: Friday, February 02, 2007 12:21 PM To: [hidden email] Subject: Recoding 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. *************************** PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
Free forum by Nabble | Edit this page |