Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

transforming variable help

0 views
Skip to first unread message

Priscilla

unread,
May 16, 2008, 3:50:18 AM5/16/08
to
Hello,

I have 3 dichotomous(0=no, 1=yes) variables (never drank, ever drank
(but no drink in last year) and drank in last year) and would like to
collapse them into one variable with the 3 categories never drank,
ever drank, drank in last year. I know it involves the COMPUTE.

Priscilla

unread,
May 16, 2008, 3:51:56 AM5/16/08
to

Sorry about that, I accidentally hit the send button...., to continue,
I know the COMPUTE function is involved, but can't quite figure out
the logic. Any help appreciated.

thanks,
P

Robert Jones

unread,
May 16, 2008, 6:35:49 AM5/16/08
to

you could try something like compute newvar=a+b*2+c*3

This assumes all existing variables have no missing values

Bruce Weaver

unread,
May 16, 2008, 7:14:01 AM5/16/08
to

DO-REPEAT works well for this.

* I'll assume your 3 variables are called D1, D2, and D3.
* The new variable will be called DRINK.

do repeat d = d1 to d3 / #i = 1 to 3 .
- if d drink = #i.
end repeat.
exe.
format drink (f1.0).
val lab drink
1 'Never drank'
2 'Drank, but not in last year'
3 'Drank in last year'
.

--
Bruce Weaver
bwe...@lakeheadu.ca
www.angelfire.com/wv/bwhomedir
"When all else fails, RTFM."

Richard Ulrich

unread,
May 16, 2008, 5:50:46 PM5/16/08
to

That Question number two is a dilly.

"Drank, but not in the last year: Yes/No".

If they never drank, there is not a right answer, since
the answer would be No to the first part and Yes to the second.

Do they skip Question two when "Never drank" is Yes?

I think you have to pay attention to the coding, and
the combination of answers that you actually received.

You can combine all eight possibilities (2x2x2) into one
variable by computing

compute tempdr= v1 + 2*v2 + 4*v3 .

... and then use Recode/INTO= to put the answers into
appropriate categories.

--
Rich Ulrich

http://www.pitt.edu/~wpilib/index.html

j.c...@uwinnipeg.ca

unread,
May 18, 2008, 12:37:14 PM5/18/08
to

Below I have implemented Richard's and Bruce's approach, and added one
of my own. One issue is what to do with inconsistent patterns. Mine
and Richard's below encode inconsistencies as 0. Bruce's approach
gives priority to certain questions, which could be a reasonable
assumption. I would probably encode the 8 conditions as in Richard's
approach (see v8 in program) to determine extent of inconsistent
responding.

Take care
Jim

*0 = no, 1 = yes.
*v1 = never drank.
*v2 = drank, not in last year.
*v3 = drank in last year.
*desired recoding.
*0 0 0 = inconsistent.
*0 0 1 = 1 drank in last year.
*0 1 0 = 2 drank but not in last year.
*0 1 1 = inconsistent.
*1 0 0 = 3 never drank.
*1 0 1 = inconsistent.
*1 1 0 = inconsistent.
*1 1 1 = inconsistent.
data list free / v1 v2 v3.
begin data
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
end data.

*jim's approach (inconsistent = 0).
comp new = ((v1 = 1) and (v2 = 0) and (v3 = 0))*3 +
((v1 = 0) and (v2 = 1) and (v3 = 0))*2 +
((v1 = 0) and (v2 = 0) and (v3 = 1))*1.

*richard's approach (assumes inconsistent = 0).
comp v8 = v1 + v2*2 + v3*4.
recode v8 (4 = 1) (2 = 2) (1 = 3) (else = 0) into new2.

*bruce's proposal (modified slightly to reorder new3).
do repeat v = v1 to v3 / #i = 1 to 3 .
- if v = 1 new3 = (4 - #i).
end repeat.

format v1 to new3(f1.0).
missing values new new2 new3 (0).
list.

v1 v2 v3 new v8 new2 new3
0 0 0 0 0 0 .
0 0 1 1 4 1 1
0 1 0 2 2 2 2
0 1 1 0 6 0 1
1 0 0 3 1 3 3
1 0 1 0 5 0 1
1 1 0 0 3 0 2
1 1 1 0 7 0 1

freq new new3.
new new3
N Valid 3 7
Missing 5 1

new
Frequency Percent Valid Percent Cumulative
Percent
Valid 1 1 12.5 33.3 33.3
2 1 12.5 33.3 66.7
3 1 12.5 33.3 100.0
Total 3 37.5 100.0
Missing 0 5 62.5

Total 8 100.0

new3
Frequency Percent Valid Percent Cumulative
Percent
Valid 1 4 50.0 57.1 57.1
2 2 25.0 28.6 85.7
3 1 12.5 14.3 100.0
Total 7 87.5 100.0
Missing System 1 12.5
Total 8 100.0


James M. Clark
Professor of Psychology
204-786-9757
204-774-4134 Fax
j.c...@uwinnipeg.ca

Mark Ebermann

unread,
May 20, 2008, 6:10:03 AM5/20/08
to
On Fri, 16 May 2008 04:14:01 -0700 (PDT), Bruce Weaver
<bwe...@lakeheadu.ca> wrote:

>
>DO-REPEAT works well for this.
>
>* I'll assume your 3 variables are called D1, D2, and D3.
>* The new variable will be called DRINK.
>
>do repeat d = d1 to d3 / #i = 1 to 3 .
>- if d drink = #i.
>end repeat.
>exe.
>format drink (f1.0).
>val lab drink
> 1 'Never drank'
> 2 'Drank, but not in last year'
> 3 'Drank in last year'
>.

How could one adapt this code to convert a dichotmous multiple
response set to a category multiple response set?

Mark Ebermann

unread,
May 20, 2008, 6:37:10 AM5/20/08
to
On Tue, 20 May 2008 10:10:03 GMT, Mark Ebermann <cfis...@aachener.de>
wrote:

Please ignore this request, I've worked it out. Thank you, Bruce.

Bruce Weaver

unread,
May 20, 2008, 7:24:50 AM5/20/08
to
On May 20, 6:37 am, Mark Ebermann <cfisc...@aachener.de> wrote:

> On Tue, 20 May 2008 10:10:03 GMT, Mark Ebermann <cfisc...@aachener.de>
> wrote:
>

>
> >How could one adapt this code to convert a dichotmous multiple
> >response set to a category multiple response set?
>
> Please ignore this request, I've worked it out. Thank you, Bruce.


Mark, would you mind posting your code? The rest of us might learn
something from it. Thanks.

Mark Ebermann

unread,
May 20, 2008, 7:36:39 AM5/20/08
to
On Tue, 20 May 2008 04:24:50 -0700 (PDT), Bruce Weaver
<bwe...@lakeheadu.ca> wrote:

>On May 20, 6:37 am, Mark Ebermann <cfisc...@aachener.de> wrote:
>> On Tue, 20 May 2008 10:10:03 GMT, Mark Ebermann <cfisc...@aachener.de>
>> wrote:
>>
>
>>
>> >How could one adapt this code to convert a dichotmous multiple
>> >response set to a category multiple response set?
>>
>> Please ignore this request, I've worked it out. Thank you, Bruce.
>
>
>Mark, would you mind posting your code? The rest of us might learn
>something from it. Thanks.

Here you go...

do repeat d = VAR00001 to VAR00010 / #i = 1 to 10 .
- if d d = #i.
end repeat.
exe.

It only changes the 1s from the original and doesn't delete the 0s . I
use this data outside of SPSS and don't need to do things like this or
account for cases where all values are false.

Priscilla

unread,
May 20, 2008, 1:49:32 PM5/20/08
to
On May 20, 1:36 pm, Mark Ebermann <cfisc...@aachener.de> wrote:
> On Tue, 20 May 2008 04:24:50 -0700 (PDT), Bruce Weaver
>

Thanks for the help. Fortunately there were no inconsistencies in the
data since the "original" dichotomous variables were recodes of the
survey questions, so following Jim's suggestion made it quite simple.
Thanks for helping me see the logic.

0 new messages