|
I have set up an online questionnaire where to answer some of the
(categorical) questions participants have to select one (and only one) of three possible responses. For some reason, the online survey software I'm using is coding responses into three separate dichotomous variables -- so, the raw data looks something like the following: q1a q1b q1c 1 . . . . 1 . 1 . . . 1 . . 1 . . 1 1 . . . . 1 . . 1 1 . . 1 . . . 1 . . 1 . where the dots represent missing data. I've been trying to use COMPUTE to create a new variable with the formula [q1a + (q1b * 2) + (q1b * 3)], in order to obtain a single quantitative variable with values 1,2,3. This doesn't work, as far as I understand because of the missing values. I'm at wit's end, and would appreciate any help on this as the database is quite large and I really don't want to end up doing this by hand! All the best, Nicola Knight |
|
Nicola,
One simple way is to recode the missing values as zeroes and then apply your formula: RECODE q1a q1b q1c (SYSMIS=0). COMPUTE newvar = q1a + (q1b * 2) + (q1b * 3). Hector -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of N Knight Sent: 25 June 2007 11:08 To: [hidden email] Subject: Help with COMPUTE I have set up an online questionnaire where to answer some of the (categorical) questions participants have to select one (and only one) of three possible responses. For some reason, the online survey software I'm using is coding responses into three separate dichotomous variables -- so, the raw data looks something like the following: q1a q1b q1c 1 . . . . 1 . 1 . . . 1 . . 1 . . 1 1 . . . . 1 . . 1 1 . . 1 . . . 1 . . 1 . where the dots represent missing data. I've been trying to use COMPUTE to create a new variable with the formula [q1a + (q1b * 2) + (q1b * 3)], in order to obtain a single quantitative variable with values 1,2,3. This doesn't work, as far as I understand because of the missing values. I'm at wit's end, and would appreciate any help on this as the database is quite large and I really don't want to end up doing this by hand! All the best, Nicola Knight |
|
In reply to this post by N Knight
Hi Nicola,
new file. data list /id 1 q1a 2 q1b 3 q1c 4 q1d 5. begin data 11 1 1 2 11 3 1 1 41111 end data. vector v = q1a to q1d / tmp(4). loop #i = 1 to 4. if ~miss(v(#i)) tmp(#i)=#i. end loop. exe. hth, Vlad. On 6/25/07, N Knight <[hidden email]> wrote: > > I have set up an online questionnaire where to answer some of the > (categorical) questions participants have to select one (and only one) > of three possible responses. For some reason, the online survey software > I'm using is coding responses into three separate dichotomous variables > -- so, the raw data looks something like the following: > > q1a q1b q1c > 1 . . > . . 1 > . 1 . > . . 1 > . . 1 > . . 1 > 1 . . > . . 1 > . . 1 > 1 . . > 1 . . > . 1 . > . 1 . > > where the dots represent missing data. I've been trying to use COMPUTE > to create a new variable with the formula [q1a + (q1b * 2) + (q1b * 3)], > in order to obtain a single quantitative variable with values 1,2,3. > This doesn't work, as far as I understand because of the missing values. > I'm at wit's end, and would appreciate any help on this as the database > is quite large and I really don't want to end up doing this by hand! > > All the best, > > Nicola Knight > -- Vlad Simion Data Analyst Tel: +40 720130611 |
|
In reply to this post by N Knight
You can break the calculation into steps:
COMPUTE score = q1a. IF q1b = 1 score = 2. IF q1c = 1 score = 3. Or you can use the SUM function to bypass the missing values COMPUTE score1 = SUM(q1a,q1b*2,q1c*3). -- jim -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of N Knight Sent: Monday, June 25, 2007 9:08 AM To: [hidden email] Subject: Help with COMPUTE I have set up an online questionnaire where to answer some of the (categorical) questions participants have to select one (and only one) of three possible responses. For some reason, the online survey software I'm using is coding responses into three separate dichotomous variables -- so, the raw data looks something like the following: q1a q1b q1c 1 . . . . 1 . 1 . . . 1 . . 1 . . 1 1 . . . . 1 . . 1 1 . . 1 . . . 1 . . 1 . where the dots represent missing data. I've been trying to use COMPUTE to create a new variable with the formula [q1a + (q1b * 2) + (q1b * 3)], in order to obtain a single quantitative variable with values 1,2,3. This doesn't work, as far as I understand because of the missing values. I'm at wit's end, and would appreciate any help on this as the database is quite large and I really don't want to end up doing this by hand! All the best, Nicola Knight |
|
In reply to this post by N Knight
Dear Nicola,
Indeed, the problem is missing data. The simplest modification to make your algorithm work is to use SUM function instead of "+". By default it requires only one valid argument to produce valid result. Like this: COMPUTE a=SUM(q1a, q1b*2, q1c*3). EXE. A bit more sophisticated solution (you might choose it if you have much more than 3 options to select in some question): DO REPEAT q=q1a TO q1c / n=1 TO 3. IF q=1 a=n. END REPEAT. EXE. "a" is your "integral" variable. Best, Anton > -----Original Message----- > From: SPSSX(r) Discussion [mailto:[hidden email]] > On Behalf Of N Knight > Sent: Monday, June 25, 2007 6:08 PM > To: [hidden email] > Subject: Help with COMPUTE > > I have set up an online questionnaire where to answer some of the > (categorical) questions participants have to select one (and > only one) of three possible responses. For some reason, the > online survey software I'm using is coding responses into > three separate dichotomous variables > -- so, the raw data looks something like the following: > > q1a q1b q1c > 1 . . > . . 1 > . 1 . > . . 1 > . . 1 > . . 1 > 1 . . > . . 1 > . . 1 > 1 . . > 1 . . > . 1 . > . 1 . > > where the dots represent missing data. I've been trying to > use COMPUTE to create a new variable with the formula [q1a + > (q1b * 2) + (q1b * 3)], in order to obtain a single > quantitative variable with values 1,2,3. > This doesn't work, as far as I understand because of the > missing values. > I'm at wit's end, and would appreciate any help on this as > the database is quite large and I really don't want to end up > doing this by hand! > > All the best, > > Nicola Knight > |
|
In reply to this post by N Knight
Dear Hector, Vlad, Jim, and Anton,
Many thanks for your quick responses. I think using SUM is the simplest option for me; I've tried it and it works perfectly. I really appreciate your help with this -- sometimes a simple solution (or a number of them, in this case) just escapes you! All the best, Nicola Knight |
|
In reply to this post by N Knight
Hi,
Here is the syntax for that... Numeric q1 (F1). compute q1= sum(q1a * 1 , q1b * 2 , q1c * 3). exe. Kulvinder |
| Free forum by Nabble | Edit this page |
