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

Computing new variable if Var1 and Var2 are the same

7 views
Skip to first unread message

David Huffaker

unread,
Nov 23, 2009, 1:26:33 PM11/23/09
to
Hi there,

I'm trying to figure out how to compute a new dichotomous variables
based on whether two variables contain the same string. For example:

================
Var1 Var2 same?
================
123 123 1
111 122 0
111 111 1

In my data set, I have hundreds of unique IDs, but I need to figure
out the extent to which the two variables match each other.

Thanks!

Ben Pfaff

unread,
Nov 23, 2009, 1:37:06 PM11/23/09
to
David Huffaker <davet...@gmail.com> writes:

> I'm trying to figure out how to compute a new dichotomous variables
> based on whether two variables contain the same string. For example:
>
> ================
> Var1 Var2 same?
> ================
> 123 123 1
> 111 122 0
> 111 111 1

COMPUTE same = Var1 EQ Var2.
--
"Long noun chains don't automatically imply security."
--Bruce Schneier

David Huffaker

unread,
Nov 23, 2009, 2:11:16 PM11/23/09
to
Thanks, Ben! Worked like a charm.

Art Kendall

unread,
Nov 23, 2009, 2:53:03 PM11/23/09
to
The example syntax below should cover many of the possible meanings.
test 1 tells whether they are exactly equal.
test 2 tells whether they the non-blank portions of the string are equal.
test 3 tells whether either string contains the other even if the trimmed strings are not equal.

It does not test whether  there is any substring in common such as 12345 and 34567 both contain 345.


data list list/ var1 (a7) var2(a6).
begin data
'    123' '123   '
'123' '123'
'123    ' '123   '
' 123 ' ' 123 '
'111' '122'
'111' '111'
' 111' '111'
' 111' '111x'
' x111' '111'
end data.
numeric test1 to test3 (f1).
compute test1 = var1 eq var2.
compute test2 = ltrim(rtrim(var1)) eq ltrim(rtrim(var2)).
compute test3 = index(var2,ltrim(rtrim(var1))) gt 0 or index(var1,ltrim(rtrim(var2))) gt 0.
LIST .

Art Kendall
Social Research Consultants
0 new messages