How to select cases with same value in one variable but at least one value in two other variables in SPSS?

Viewed 49

I have a dataset in SPSS as follows:

enter image description here

Key variables:

  • k_hidp is the household identifier
  • pidp_parent is the personal identifier of the parent
  • pidp_child is the personal identifier of the child

I would like to extract all data from households with at least one valid value in pidp_parent and one valid value in pidp_child.

For example in the above data excerpt: On line 6-7, we have household #68639220. I would like to extract data from both line 6 & 7, how could I do so in SPSS?

Thank you.

1 Answers

The following aggregate function will identify the maximum child ID and maximum parent ID for each household. Households where all parent IDs are missing will show missing in maximum parent ID and we will know to deselect them - same for child.

aggregate out=* mode=addvariables/break=k_hidp
     /mxParent mxChild=max(pidp_parent pidp_child).
compute forAnalysis=not missing(mxParent) and not missing(mxChild).

The new variable forAnalysis has value 1 for households that have at least one valid parent ID and one valid child ID. You can use if to select or filter or otherwise identify the lines relevant for analysis.

Related