Providing code review is beyond the purview of IPUMS user support. However, I can share some general feedback based on what you have shared and highlight things you might consider moving forward.
It looks like you are applying the following logic in the steps to identify same-sex couples:
- keep only the householder records
- keep householder records whose sex is the same as their spouse (as assigned by IPUMS family interrelationship variables)
- keep if the relationship reported by their IPUMS-assigned spouse is either “Spouse” or “Unmarried partner”
- create flag/dummy variable that is equal to 1 for persons in this dataset
Note that this approach creates a dataset that consists of householders only; the spouses are not included in the dataset. This may be problematic depending on what your next steps are. For example, if you wanted to use this as the same-sex dataset and try to sum income across both members of the couple you would only capture the householder’s income.
This approach also eliminates any same-sex couples who are otherwise identified by IPUMS family interrelationship variables who are not the householder and their spouse/unmarried partner (e.g., if a “sister” and “sister-in-law” are both in the household and both report being married and are the only persons who report being married in the household, the IPUMS algorithm will link them). By restricting to householders only, you reduce issues of comparability over time, but I am noting that IPUMS family interrelationship variables will identify same-sex couples in some years outside of the householder/spouse and householder/unmarried partner pairings.
Your code for identifying different-sex couples uses a different approach from how you assigned the same-sex couples; it isn’t immediately clear to me why altered the code for this group rather than replicating the code you use for the same-sex couples with modifications around sex_sp. I will note, however, that SPRULE value of 11 can include same-sex partners, so this is not excluding same-sex couples. It also looks like your current code keeps only the spouses but omits the householders with whom they are partnered from the data.
There is sample code from IPUMS USA for attaching information about a spouse or parent onto a person record (scroll towards bottom of the page I linked above for the sample code). While the code is explicitly about creating the functionality that the “attach features” aspect of the extract system creates for you, you may find these code examples helpful.