Combining Variables

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Scott_L
Posts: 3
Joined: Mon Feb 10, 2014 9:13 pm

Combining Variables

Postby Scott_L » Tue Feb 11, 2014 3:09 am

If this is answered somewhere (I am sure it is) I have looked and not found it, but it seems fairly simple, so I am sure it is. I had a course on syntax about 4 years ago on STATA, and am now in dissertation on SPSS. While I know they are similar, 4 years and a different software program has me in loops. I am Scott, and I am sure I will be on here a lot Thanks (or sorry) in advance!!

So I used Survey Monkey and employed their skip logic with my survey. What this means is that I have a bunch of questions duplicated on the questionnaire and need to combine variables. I am having a tough time getting the data right. I am going to list all of my problems in hopes that people can jump in and help me where they can. In a year I will look back on this and probably think it was silly not figuring this out on my own...

1. String Data. After I separate my respondents into groups and ask them questions, I had to collect addresses for a potential phase 2 study. I therefore have 4 different address variables that I need to combine into one. It is not possible for a respondent to answer this in two different sections, so I simply need to condense it into one variable.
_____________Address 1 | Address 2 | Address 3 | Address 4 ||| New Address Variable
Respondent 1........(X)...............................................|||...........(X)
Respondent 2......................(X).................................|||...........(X)
Respondent 3.....................................(X)..................|||...........(X)
Respondent 4................................................(X).......|||............(X)
I have tried compute and string to no avail!!

Here is my latest attempt:

String Address (A1200).
RECODE q0032_0003 (ELSE=COPY) INTO Address
RECODE q0033_0003 (ELSE=COPY) INTO Address
RECODE q0034_0003 (ELSE=COPY) INTO Address
RECODE q0035_0003 (ELSE=COPY) INTO Address.


I have tried all sorts of stuff in the (ELSE=COPY) and this is a bit creative, but tried '+', ',', 'nothing', etc.... I am now getting this error:

String Address (A40).

>Error # 4822 in column 8. Text: Address
>A variable with this name is already defined.
>Execution of this command stops.
RECODE q0032_0003 INTO Address
RECODE q0033_0003 INTO Address
RECODE q0034_0003 INTO Address
RECODE q0035_0003 INTO Address.

>Error # 4631 in column 20. Text: INTO
>On the RECODE command, the list of variables to be recoded includes the name
>of a nonexistent variable.
>Execution of this command stops.
String Address (A40).
RECODE q0032_0003 INTO Address
RECODE q0033_0003 INTO Address
RECODE q0034_0003 INTO Address
RECODE q0035_0003 INTO Address.

>Error # 4631 in column 20. Text: INTO
>On the RECODE command, the list of variables to be recoded includes the name
>of a nonexistent variable.
- And actually I have checked and double checked, and the variables are correct...
>Execution of this command stops.
String Address (A1200).
RECODE q0032_0003 (ELSE=COPY) INTO Address
RECODE q0033_0003 (ELSE=COPY) INTO Address
RECODE q0034_0003 (ELSE=COPY) INTO Address
RECODE q0035_0003 (ELSE=COPY) INTO Address.

>Warning # 4684 in column 37. Text: Address
>On the RECODE command, the list of variables following the keyword INTO
>includes a string variable which is not of sufficient width to accept the
>longest string value generated by the value specifications. Long values will
>be truncated to the length of the variables.

>Error # 4678 in column 2. Text: RECODE
>On the RECODE command, a variable following the keyword INTO is undefined,
>although the value specifications generate string values. New string
>variables must be explicitly declared on the STRING command.
>Execution of this command stops.


--------------------------------------------
2. Race....broken into dichotomous variables, but same deal. Since its not string or categorical, I tried to use the 'recode into different variable' option, but it would not allow me to send two variables to the same new variable (error: 'Variable Name Duplicates Another Variable being created') Without making this longer, I need to merge about every category together (string dichotomy, categorical, etc.) and if I can get the first few right, I am sure the others will start to come easier....
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Combining Variables

Postby GerineL » Tue Feb 11, 2014 10:16 am

Scott_L wrote: 1. String Data. After I separate my respondents into groups and ask them questions, I had to collect addresses for a potential phase 2 study. I therefore have 4 different address variables that I need to combine into one. It is not possible for a respondent to answer this in two different sections, so I simply need to condense it into one variable.
_____________Address 1 | Address 2 | Address 3 | Address 4 ||| New Address Variable
Respondent 1........(X)...............................................|||...........(X)
Respondent 2......................(X).................................|||...........(X)
Respondent 3.....................................(X)..................|||...........(X)
Respondent 4................................................(X).......|||............(X)
I have tried compute and string to no avail!!
string newvariable(a1200).
execute.

if (adress1 ~= " ") newvariable = newadress1.
if (adress2 ~= " ") newvariable = newadress2.
if (adress3 ~= " ") newvariable= newadress3.
if (adress4 ~= " ") newvariable= newadress4.
execute.
--------------------------------------------
2. Race....broken into dichotomous variables, but same deal. Since its not string or categorical, I tried to use the 'recode into different variable' option, but it would not allow me to send two variables to the same new variable (error: 'Variable Name Duplicates Another Variable being created') Without making this longer, I need to merge about every category together (string dichotomy, categorical, etc.) and if I can get the first few right, I am sure the others will start to come easier....
i would replace system missings by a number that is higher than any entry you have. then use the if code.

so for instance

recode var1 var2 var3 (sysmis = 999999).
execute.

if (var1 < 999999) newvar = var1.
etc.
Scott_L
Posts: 3
Joined: Mon Feb 10, 2014 9:13 pm

Re: Combining Variables

Postby Scott_L » Tue Feb 11, 2014 10:54 am

Thank You!!! That little bit should take me through quite a few steps and it worked!!

Who is online

Users browsing this forum: No registered users and 1 guest

cron