Test for equal values across 17 variables

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Test for equal values across 17 variables

james.moffitt

I have 17 contiguous numeric variables named acme1 to acme17.

Acme1 is populated with a numeric value for each case in my file but the number of the remaining 16 variables that are populated differs from case to case.

 

In other words, for case 1, acme1 to acme6 may be populated with acme7 to acme 17 system missing.

For case 2, acme1 to acme12 may be populated with acme13 to acme 17 system missing.

For case 3, acme1 may be populated with acme2 to acme17 system missing.

For case 4, all 17 variables may be populated.

 

Does anyone know how to determine, for each case, whether all the populated variables within the acme1 to acme17 sequence are populated with the same value?

 

I’d like some syntax to create another variable named OK which is coded with a 1 if all the variables from acme1 to acme17 which contain a value contain the same value and a 2 if they don’t.

 

Here’s some test data.

 

DATA LIST LIST (",")/ id acme1 to acme17.

BEGIN DATA

1,42,42,42,42,,,,,,,,,,,,,,

2,6,6,6,6,6,6,6,6,6,6,7,6,6,6,6,,,

3,62,62,62,62,62,62,62,,,,,,,,,,,

4,7,7,7,7,7,7,8,,,,,,,,,,,

5,2,,,,,,,,,,,,,,,,,

END DATA.

 

Effective syntax would create the variable “OK” which  would be coded with a 1 for case 1, a 2 for case 2, a 1 for case 3, a 2 for case 4, and a 1 for case 5.

 

Thanks for your help.

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Test for equal values across 17 variables

Art Kendall
the syntax below will do what you said but treats values as user missing when it is known why the value is missing.  That way sysmis can be reserved for its debugging role when the syntax asks the program to do something it cannot do,
Open a new instance of SPSS.  Copy the syntax below to a syntax file. Click <run>. Click <all>.

Art Kendall
Social Research Consultants


set blanks 0 .

DATA LIST LIST (",")/ id acme1 to acme17.
BEGIN DATA
1,42,42,42,42,,,,,,,,,,,,,,
2,6,6,6,6,6,6,6,6,6,6,7,6,6,6,6,,,
3,62,62,62,62,62,62,62,,,,,,,,,,,
4,7,7,7,7,7,7,8,,,,,,,,,,,
5,2,,,,,,,,,,,,,,,,,
END DATA.
formats acme1 to acme17 (f2).
missing values acme1 to acme17 (0).
value labels acme1 to acme17 0 'blank on input'.
do if nvalid(acme1 to acme17) eq 1 or (nvalid(acme1 to acme17) ge 2 and sd.2(acme1 to acme17) eq 0).
compute ok =1.
ELSE .
compute ok=2.
end if.
formats ok (f1).
frequencies vars = ok.

Art Kendall
Social Research Consultants



[hidden email] wrote:

I have 17 contiguous numeric variables named acme1 to acme17.

Acme1 is populated with a numeric value for each case in my file but the number of the remaining 16 variables that are populated differs from case to case.

 

In other words, for case 1, acme1 to acme6 may be populated with acme7 to acme 17 system missing.

For case 2, acme1 to acme12 may be populated with acme13 to acme 17 system missing.

For case 3, acme1 may be populated with acme2 to acme17 system missing.

For case 4, all 17 variables may be populated.

 

Does anyone know how to determine, for each case, whether all the populated variables within the acme1 to acme17 sequence are populated with the same value?

 

I’d like some syntax to create another variable named OK which is coded with a 1 if all the variables from acme1 to acme17 which contain a value contain the same value and a 2 if they don’t.

 

Here’s some test data.

 

DATA LIST LIST (",")/ id acme1 to acme17.

BEGIN DATA

1,42,42,42,42,,,,,,,,,,,,,,

2,6,6,6,6,6,6,6,6,6,6,7,6,6,6,6,,,

3,62,62,62,62,62,62,62,,,,,,,,,,,

4,7,7,7,7,7,7,8,,,,,,,,,,,

5,2,,,,,,,,,,,,,,,,,

END DATA.

 

Effective syntax would create the variable “OK” which  would be coded with a 1 for case 1, a 2 for case 2, a 1 for case 3, a 2 for case 4, and a 1 for case 5.

 

Thanks for your help.

 

 

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Test for equal values across 17 variables

james.moffitt

Art:

Thanks so much. The code is exactly what I need. Using NVALID and calculating a standard deviation on the valid values to test equality was very clever. My only question concerns the standard deviation specification. What is the significance of the 2 in “sd.2”?

Jim

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall
Sent: Thursday, February 19, 2009 12:00 PM
To: [hidden email]
Subject: Re: Test for equal values across 17 variables

 

the syntax below will do what you said but treats values as user missing when it is known why the value is missing.  That way sysmis can be reserved for its debugging role when the syntax asks the program to do something it cannot do,
Open a new instance of SPSS.  Copy the syntax below to a syntax file. Click <run>. Click <all>.

Art Kendall
Social Research Consultants


set blanks 0 .

DATA LIST LIST (",")/ id acme1 to acme17.
BEGIN DATA
1,42,42,42,42,,,,,,,,,,,,,,
2,6,6,6,6,6,6,6,6,6,6,7,6,6,6,6,,,
3,62,62,62,62,62,62,62,,,,,,,,,,,
4,7,7,7,7,7,7,8,,,,,,,,,,,
5,2,,,,,,,,,,,,,,,,,
END DATA.
formats acme1 to acme17 (f2).
missing values acme1 to acme17 (0).
value labels acme1 to acme17 0 'blank on input'.
do if nvalid(acme1 to acme17) eq 1 or (nvalid(acme1 to acme17) ge 2 and sd.2(acme1 to acme17) eq 0).
compute ok =1.
ELSE .
compute ok=2.
end if.
formats ok (f1).
frequencies vars = ok.

Art Kendall
Social Research Consultants


[hidden email] wrote:

I have 17 contiguous numeric variables named acme1 to acme17.


Acme1 is populated with a numeric value for each case in my file but the number of the remaining 16 variables that are populated differs from case to case.

 

In other words, for case 1, acme1 to acme6 may be populated with acme7 to acme 17 system missing.

For case 2, acme1 to acme12 may be populated with acme13 to acme 17 system missing.

For case 3, acme1 may be populated with acme2 to acme17 system missing.

For case 4, all 17 variables may be populated.

 

Does anyone know how to determine, for each case, whether all the populated variables within the acme1 to acme17 sequence are populated with the same value?

 

I’d like some syntax to create another variable named OK which is coded with a 1 if all the variables from acme1 to acme17 which contain a value contain the same value and a 2 if they don’t.

 

Here’s some test data.

 

DATA LIST LIST (",")/ id acme1 to acme17.

BEGIN DATA

1,42,42,42,42,,,,,,,,,,,,,,

2,6,6,6,6,6,6,6,6,6,6,7,6,6,6,6,,,

3,62,62,62,62,62,62,62,,,,,,,,,,,

4,7,7,7,7,7,7,8,,,,,,,,,,,

5,2,,,,,,,,,,,,,,,,,

END DATA.

 

Effective syntax would create the variable “OK” which  would be coded with a 1 for case 1, a 2 for case 2, a 1 for case 3, a 2 for case 4, and a 1 for case 5.

 

Thanks for your help.

 

 

Reply | Threaded
Open this post in threaded view
|

Re: Test for equal values across 17 variables

Art Kendall
the .n suffix to the stat functions indicates how many valid values there must be to compute the function. 

Art

[hidden email] wrote:

Art:

Thanks so much. The code is exactly what I need. Using NVALID and calculating a standard deviation on the valid values to test equality was very clever. My only question concerns the standard deviation specification. What is the significance of the 2 in “sd.2”?

Jim

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Art Kendall
Sent: Thursday, February 19, 2009 12:00 PM
To: [hidden email]
Subject: Re: Test for equal values across 17 variables

 

the syntax below will do what you said but treats values as user missing when it is known why the value is missing.  That way sysmis can be reserved for its debugging role when the syntax asks the program to do something it cannot do,
Open a new instance of SPSS.  Copy the syntax below to a syntax file. Click <run>. Click <all>.

Art Kendall
Social Research Consultants


set blanks 0 .

DATA LIST LIST (",")/ id acme1 to acme17.
BEGIN DATA
1,42,42,42,42,,,,,,,,,,,,,,
2,6,6,6,6,6,6,6,6,6,6,7,6,6,6,6,,,
3,62,62,62,62,62,62,62,,,,,,,,,,,
4,7,7,7,7,7,7,8,,,,,,,,,,,
5,2,,,,,,,,,,,,,,,,,
END DATA.
formats acme1 to acme17 (f2).
missing values acme1 to acme17 (0).
value labels acme1 to acme17 0 'blank on input'.
do if nvalid(acme1 to acme17) eq 1 or (nvalid(acme1 to acme17) ge 2 and sd.2(acme1 to acme17) eq 0).
compute ok =1.
ELSE .
compute ok=2.
end if.
formats ok (f1).
frequencies vars = ok.

Art Kendall
Social Research Consultants


[hidden email] wrote:

I have 17 contiguous numeric variables named acme1 to acme17.


Acme1 is populated with a numeric value for each case in my file but the number of the remaining 16 variables that are populated differs from case to case.

 

In other words, for case 1, acme1 to acme6 may be populated with acme7 to acme 17 system missing.

For case 2, acme1 to acme12 may be populated with acme13 to acme 17 system missing.

For case 3, acme1 may be populated with acme2 to acme17 system missing.

For case 4, all 17 variables may be populated.

 

Does anyone know how to determine, for each case, whether all the populated variables within the acme1 to acme17 sequence are populated with the same value?

 

I’d like some syntax to create another variable named OK which is coded with a 1 if all the variables from acme1 to acme17 which contain a value contain the same value and a 2 if they don’t.

 

Here’s some test data.

 

DATA LIST LIST (",")/ id acme1 to acme17.

BEGIN DATA

1,42,42,42,42,,,,,,,,,,,,,,

2,6,6,6,6,6,6,6,6,6,6,7,6,6,6,6,,,

3,62,62,62,62,62,62,62,,,,,,,,,,,

4,7,7,7,7,7,7,8,,,,,,,,,,,

5,2,,,,,,,,,,,,,,,,,

END DATA.

 

Effective syntax would create the variable “OK” which  would be coded with a 1 for case 1, a 2 for case 2, a 1 for case 3, a 2 for case 4, and a 1 for case 5.

 

Thanks for your help.

 

 

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Test for equal values across 17 variables

Oliver, Richard

This is a very cool solution.

 


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Art Kendall
Sent: Friday, February 20, 2009 12:33 PM
To: [hidden email]
Subject: Re: Test for equal values across 17 variables

 

the .n suffix to the stat functions indicates how many valid values there must be to compute the function. 

Art

[hidden email] wrote:

Art:

Thanks so much. The code is exactly what I need. Using NVALID and calculating a standard deviation on the valid values to test equality was very clever. My only question concerns the standard deviation specification. What is the significance of the 2 in “sd.2”?

Jim

 

From: SPSSX(r) Discussion [[hidden email]] On Behalf Of Art Kendall
Sent: Thursday, February 19, 2009 12:00 PM
To: [hidden email]
Subject: Re: Test for equal values across 17 variables

 

the syntax below will do what you said but treats values as user missing when it is known why the value is missing.  That way sysmis can be reserved for its debugging role when the syntax asks the program to do something it cannot do,
Open a new instance of SPSS.  Copy the syntax below to a syntax file. Click <run>. Click <all>.

Art Kendall
Social Research Consultants


set blanks 0 .

DATA LIST LIST (",")/ id acme1 to acme17.
BEGIN DATA
1,42,42,42,42,,,,,,,,,,,,,,
2,6,6,6,6,6,6,6,6,6,6,7,6,6,6,6,,,
3,62,62,62,62,62,62,62,,,,,,,,,,,
4,7,7,7,7,7,7,8,,,,,,,,,,,
5,2,,,,,,,,,,,,,,,,,
END DATA.
formats acme1 to acme17 (f2).
missing values acme1 to acme17 (0).
value labels acme1 to acme17 0 'blank on input'.
do if nvalid(acme1 to acme17) eq 1 or (nvalid(acme1 to acme17) ge 2 and sd.2(acme1 to acme17) eq 0).
compute ok =1.
ELSE .
compute ok=2.
end if.
formats ok (f1).
frequencies vars = ok.

Art Kendall
Social Research Consultants


[hidden email] wrote:

I have 17 contiguous numeric variables named acme1 to acme17.



Acme1 is populated with a numeric value for each case in my file but the number of the remaining 16 variables that are populated differs from case to case.

 

In other words, for case 1, acme1 to acme6 may be populated with acme7 to acme 17 system missing.

For case 2, acme1 to acme12 may be populated with acme13 to acme 17 system missing.

For case 3, acme1 may be populated with acme2 to acme17 system missing.

For case 4, all 17 variables may be populated.

 

Does anyone know how to determine, for each case, whether all the populated variables within the acme1 to acme17 sequence are populated with the same value?

 

I’d like some syntax to create another variable named OK which is coded with a 1 if all the variables from acme1 to acme17 which contain a value contain the same value and a 2 if they don’t.

 

Here’s some test data.

 

DATA LIST LIST (",")/ id acme1 to acme17.

BEGIN DATA

1,42,42,42,42,,,,,,,,,,,,,,

2,6,6,6,6,6,6,6,6,6,6,7,6,6,6,6,,,

3,62,62,62,62,62,62,62,,,,,,,,,,,

4,7,7,7,7,7,7,8,,,,,,,,,,,

5,2,,,,,,,,,,,,,,,,,

END DATA.

 

Effective syntax would create the variable “OK” which  would be coded with a 1 for case 1, a 2 for case 2, a 1 for case 3, a 2 for case 4, and a 1 for case 5.

 

Thanks for your help.