DO REPEAT r=Q1 to Q100 /newVar=R1 to R100. DO IF(r < 3). COMPUTE newVar=1. END IF. DO IF (r > 2). COMPUTE newVar = 2. END IF. end repeat. exe. I have the code above that allows me to collapse hundreds of categorical variables into a dichotomous variable. It will successfully recode 100 variables from Q1 to Q100 to recoded variables R1 to R100. Is there a simple way to copy the value labels from Q1 to R1 and Q2 to R2? Each corresponds to the other, but SPSS gives me an error saying that VARIABLE LABELS is not a command allowed inside a DO REPEAT code block. So if Q1 is “Measure of Attitude for Group 1” then R1 will also be “Measure of Attitude for Group 1” and so on? Gareth Edwards 1155 16th St., NW | Washington | DC 20036 |
you could try:
apply dictionary from * /source variables=varlist /target variables=varlist /varinfo vallabels=replace. Rick Oliver Senior Information Developer IBM Business Analytics (SPSS) E-mail: [hidden email] From: Gareth Edwards <[hidden email]> To: [hidden email] Date: 06/04/2015 01:26 PM Subject: Use DO REPEAT to copy variable labels Sent by: "SPSSX(r) Discussion" <[hidden email]> DO REPEAT r=Q1 to Q100 /newVar=R1 to R100. DO IF(r < 3). COMPUTE newVar=1. END IF. DO IF (r > 2). COMPUTE newVar = 2. END IF. end repeat. exe. I have the code above that allows me to collapse hundreds of categorical variables into a dichotomous variable. It will successfully recode 100 variables from Q1 to Q100 to recoded variables R1 to R100. Is there a simple way to copy the value labels from Q1 to R1 and Q2 to R2? Each corresponds to the other, but SPSS gives me an error saying that VARIABLE LABELS is not a command allowed inside a DO REPEAT code block. So if Q1 is “Measure of Attitude for Group 1” then R1 will also be “Measure of Attitude for Group 1” and so on? Gareth Edwards Senior Research Associate | Research & Market Insights 1155 16th St., NW | Washington | DC 20036 T 202-872-4433 | F 202-872-6337 www.acs.org –––––––––––––––––––– ACS Chemistry for Life ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@...(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
|
Also the code could be re-written more parsimoniously as: DO REPEAT r=Q1 to Q100 /newVar=R1 to R100. COMPUTE newVar=(r>2)+1. END REPEAT. Which I would presume would run faster also, would make a difference for large datasets. On Thu, 4 Jun 2015 at 19:55, Rick Oliver <[hidden email]> wrote:
=====================
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
you could try: |
In reply to this post by Gareth Edwards-7
Unfortunately, you can't do this with APPLY
DICTIONARY, because it doesn't support parallel copies, but a tiny Python
program can do the job.
begin program. import spssaux vardict = spssaux.VariableDict() for i in range(1, 100): vardict["R"+str(i)].ValueLabels = vardict["Q"+str(i)].ValueLabels end program. Jon Peck (no "h") aka Kim Senior Software Engineer, IBM [hidden email] phone: 720-342-5621 From: Gareth Edwards <[hidden email]> To: [hidden email] Date: 06/04/2015 12:25 PM Subject: [SPSSX-L] Use DO REPEAT to copy variable labels Sent by: "SPSSX(r) Discussion" <[hidden email]> DO REPEAT r=Q1 to Q100 /newVar=R1 to R100. DO IF(r < 3). COMPUTE newVar=1. END IF. DO IF (r > 2). COMPUTE newVar = 2. END IF. end repeat. exe. I have the code above that allows me to collapse hundreds of categorical variables into a dichotomous variable. It will successfully recode 100 variables from Q1 to Q100 to recoded variables R1 to R100. Is there a simple way to copy the value labels from Q1 to R1 and Q2 to R2? Each corresponds to the other, but SPSS gives me an error saying that VARIABLE LABELS is not a command allowed inside a DO REPEAT code block. So if Q1 is “Measure of Attitude for Group 1” then R1 will also be “Measure of Attitude for Group 1” and so on? Gareth Edwards Senior Research Associate | Research & Market Insights 1155 16th St., NW | Washington | DC 20036 T 202-872-4433 | F 202-872-6337 www.acs.org –––––––––––––––––––– ACS Chemistry for Life ===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@... (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 |
Thanks Jon! To anyone else, the code that will copy the Variable Labels from one set of variables (Q1 to Q100) to another is below: begin program. This code will copy the variable labels from Q1 to R1, and Q2 to R2 (assuming they all already exist). This will do it for 100 variables. If you want more
or less, adjust the range(1,101). If you want to adjust the prefix for the variable, change what is in quotes. Thanks Jon! Gareth Edwards 1155 16th St., NW | Washington | DC 20036 From: Jon K Peck [mailto:[hidden email]]
Unfortunately, you can't do this with APPLY DICTIONARY, because it doesn't support parallel copies, but a tiny Python program can do the job.
===================== 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 |