Matching Cohabitating Partners to Their Characteristics in the NLSY97


STATA Code and Instructions

Please read the introductory material and steps 1 and 2 in the main tutorial before starting step 3 here.

  1. Find partner id for the 1st partner.
  2. Split 1st partner id into round number and loop number.
  3. Locate partner on partner roster collected in marriage and cohabitation section and link partner to his/her age.
  4. For partners who were in the household use the unique id to find the partner on the household roster and link partner to his/her age.
  5. For non-resident partners from prior to the date of the NLSY97 Round 1 interview, get age from the non-resident roster in Round 1.

Step 3: Find the partner id for the first partner

To find the id for the first partner, you will look at the elements of the MAR_PARTNER_LINK. The first element that contains a valid value will be the first partner id. For instance, for respondent id=7525, the first partner id (501) is stored in MAR_PARTNER_LINK_02_01 (February 2001).

In Round 10, the MAR_PARTNER_LINK array is available for the months April 1994 to May 2007.

Using Stata, sample code shows how to find the id of the first partner. The code defines a global macro that contains the elements of MAR_PARTNER_LINK. We loop through the elements of MAR_PARTNER_LINK until we find the first one that contains a valid value. I made a new variable, called firstpid, that takes the value of the 1st partner id.

global listmplink
MAR_PARTNER_LINK_01_94 MAR_PARTNER_LINK_02_94 MAR_PARTNER_LINK_03_94 MAR_PARTNER_LINK_04_94 MAR_PARTNER_LINK_05_94 MAR_PARTNER_LINK_06_94 MAR_PARTNER_LINK_07_94 MAR_PARTNER_LINK_08_94 MAR_PARTNER_LINK_09_94 MAR_PARTNER_LINK_10_94 MAR_PARTNER_LINK_11_94 MAR_PARTNER_LINK_12_94
MAR_PARTNER_LINK_01_95 MAR_PARTNER_LINK_02_95 MAR_PARTNER_LINK_03_95 MAR_PARTNER_LINK_04_95 MAR_PARTNER_LINK_05_95 MAR_PARTNER_LINK_06_95 MAR_PARTNER_LINK_07_95 MAR_PARTNER_LINK_08_95 MAR_PARTNER_LINK_09_95 MAR_PARTNER_LINK_10_95 MAR_PARTNER_LINK_11_95 MAR_PARTNER_LINK_12_95
MAR_PARTNER_LINK_01_96 MAR_PARTNER_LINK_02_96 MAR_PARTNER_LINK_03_96 MAR_PARTNER_LINK_04_96 MAR_PARTNER_LINK_05_96 MAR_PARTNER_LINK_06_96 MAR_PARTNER_LINK_07_96 MAR_PARTNER_LINK_08_96 MAR_PARTNER_LINK_09_96 MAR_PARTNER_LINK_10_96 MAR_PARTNER_LINK_11_96 MAR_PARTNER_LINK_12_96
MAR_PARTNER_LINK_01_97 MAR_PARTNER_LINK_02_97 MAR_PARTNER_LINK_03_97 MAR_PARTNER_LINK_04_97 MAR_PARTNER_LINK_05_97 MAR_PARTNER_LINK_06_97 MAR_PARTNER_LINK_07_97 MAR_PARTNER_LINK_08_97 MAR_PARTNER_LINK_09_97 MAR_PARTNER_LINK_10_97 MAR_PARTNER_LINK_11_97 MAR_PARTNER_LINK_12_97
MAR_PARTNER_LINK_01_98 MAR_PARTNER_LINK_02_98 MAR_PARTNER_LINK_03_98 MAR_PARTNER_LINK_04_98 MAR_PARTNER_LINK_05_98 MAR_PARTNER_LINK_06_98 MAR_PARTNER_LINK_07_98 MAR_PARTNER_LINK_08_98 MAR_PARTNER_LINK_09_98 MAR_PARTNER_LINK_10_98 MAR_PARTNER_LINK_11_98 MAR_PARTNER_LINK_12_98
MAR_PARTNER_LINK_01_99 MAR_PARTNER_LINK_02_99 MAR_PARTNER_LINK_03_99 MAR_PARTNER_LINK_04_99 MAR_PARTNER_LINK_05_99 MAR_PARTNER_LINK_06_99 MAR_PARTNER_LINK_07_99 MAR_PARTNER_LINK_08_99 MAR_PARTNER_LINK_09_99 MAR_PARTNER_LINK_10_99 MAR_PARTNER_LINK_11_99 MAR_PARTNER_LINK_12_99
MAR_PARTNER_LINK_01_00 MAR_PARTNER_LINK_02_00 MAR_PARTNER_LINK_03_00 MAR_PARTNER_LINK_04_00 MAR_PARTNER_LINK_05_00 MAR_PARTNER_LINK_06_00 MAR_PARTNER_LINK_07_00 MAR_PARTNER_LINK_08_00 MAR_PARTNER_LINK_09_00 MAR_PARTNER_LINK_10_00 MAR_PARTNER_LINK_11_00 MAR_PARTNER_LINK_12_00
MAR_PARTNER_LINK_01_01 MAR_PARTNER_LINK_02_01 MAR_PARTNER_LINK_03_01 MAR_PARTNER_LINK_04_01 MAR_PARTNER_LINK_05_01 MAR_PARTNER_LINK_06_01 MAR_PARTNER_LINK_07_01 MAR_PARTNER_LINK_08_01 MAR_PARTNER_LINK_09_01 MAR_PARTNER_LINK_10_01 MAR_PARTNER_LINK_11_01 MAR_PARTNER_LINK_12_01
MAR_PARTNER_LINK_01_02 MAR_PARTNER_LINK_02_02 MAR_PARTNER_LINK_03_02 MAR_PARTNER_LINK_04_02 MAR_PARTNER_LINK_05_02 MAR_PARTNER_LINK_06_02 MAR_PARTNER_LINK_07_02 MAR_PARTNER_LINK_08_02 MAR_PARTNER_LINK_09_02 MAR_PARTNER_LINK_10_02 MAR_PARTNER_LINK_11_02 MAR_PARTNER_LINK_12_02
MAR_PARTNER_LINK_01_03 MAR_PARTNER_LINK_02_03 MAR_PARTNER_LINK_03_03 MAR_PARTNER_LINK_04_03 MAR_PARTNER_LINK_05_03 MAR_PARTNER_LINK_06_03 MAR_PARTNER_LINK_07_03 MAR_PARTNER_LINK_08_03 MAR_PARTNER_LINK_09_03 MAR_PARTNER_LINK_10_03 MAR_PARTNER_LINK_11_03 MAR_PARTNER_LINK_12_03
MAR_PARTNER_LINK_01_04 MAR_PARTNER_LINK_02_04 MAR_PARTNER_LINK_03_04 MAR_PARTNER_LINK_04_04 MAR_PARTNER_LINK_05_04 MAR_PARTNER_LINK_06_04 MAR_PARTNER_LINK_07_04 MAR_PARTNER_LINK_08_04 MAR_PARTNER_LINK_09_04 MAR_PARTNER_LINK_10_04 MAR_PARTNER_LINK_11_04 MAR_PARTNER_LINK_12_04
MAR_PARTNER_LINK_01_05 MAR_PARTNER_LINK_02_05 MAR_PARTNER_LINK_03_05 MAR_PARTNER_LINK_04_05 MAR_PARTNER_LINK_05_05 MAR_PARTNER_LINK_06_05 MAR_PARTNER_LINK_07_05 MAR_PARTNER_LINK_08_05 MAR_PARTNER_LINK_09_05 MAR_PARTNER_LINK_10_05 MAR_PARTNER_LINK_11_05 MAR_PARTNER_LINK_12_05
MAR_PARTNER_LINK_01_06 MAR_PARTNER_LINK_02_06 MAR_PARTNER_LINK_03_06 MAR_PARTNER_LINK_04_06 MAR_PARTNER_LINK_05_06 MAR_PARTNER_LINK_06_06 MAR_PARTNER_LINK_07_06 MAR_PARTNER_LINK_08_06
MAR_PARTNER_LINK_09_06 MAR_PARTNER_LINK_10_06 MAR_PARTNER_LINK_11_06 MAR_PARTNER_LINK_12_06
MAR_PARTNER_LINK_01_07 MAR_PARTNER_LINK_02_07 MAR_PARTNER_LINK_03_07 MAR_PARTNER_LINK_04_07 MAR_PARTNER_LINK_05_07 ;

gen month1cohab=0;
gen firstpid=.;
foreach mplink of global listmplink { ;
quietly replace month1cohab=month1cohab+1;
gen firstpid=`mplink' if firstpid==. & `mplink'>0;
} ;


Step 4: Split 1st partner id (firstpid) into round number and loop number

The values of the MAR_PARTNER_LINK array and now the variable firstpid are the round followed by the partner number within that round. For instance, for sample member 7525, the MAR_PARTNER_LINK value in February of 2001 is 501, indicating that this partner is first listed in Round 5 and is the first partner in that round. I split the partner id into its two components—round and number within that round—and then use those 2 pieces of information to find the location of 1st partner in the list of unique partner ids from across rounds and find the partner’s age.

In Stata, code that lets you split the two pieces of information can be:

gen withinrnd=mod(firstpid,100) /* this command yields the remainder from dividing firstpid by 100*/;
gen round=(firstpid-withinrnd)/100;

The Stata code that then uses the variable “round” to tell you in which round the partner first appears. We create a variable “startinvarlist” to tell you where to start looking for the first partner can be:

gen startinvarlist=1 if round==1;
replace placeinvarlist=(round-1)*4 if round>1;

/* Note that in the code immediately above 4 is the maximum number of partners reported in any round and for simplicity I set up the list of potential partner as having 4 possibilities in each round. More explanation is provided below in step 5. */


Step 5: Locate partner on partner roster collected in marriage and cohabitation section and link partner to his/her age

Using Stata, I set up three global macros: (1) lists partners’ ids, (2) lists the partners’ unique ids, and (3) lists the partners’ ages. The first variable list, named listpid, is made up of the variables that provide the id of the respondents’ partners. A match between the value in this array and that of “firstpid” (1st partner’s id) is needed to find the partner’s age. The second variable list, named listpuid, is made up of the variables that provide the unique id of the respondents’ partners. The third variable list, named listpage, is made up of the variables that provide the age of the respondent’s partners—for partners who were not living in the respondent’s household at the time of the interview. Both of these variable lists have 40 elements; that is, 10 rows (one for each round of the data) and 4 columns (4 is the maximum number of partners that any respondent reports in a round). In some rounds, all respondents report fewer than 4 partners. In that case, there is no variable for the 4th partner’s age or unique id. I use “blank” to fill out the macro in these cases.

The sample code shows how to loop through the variable lists and find the 1st partner. The 1st partner will show up where the item number in the variable list is equal to the variable “placeinvarlist” that you created in step 4. At this location in the listpuid, you will find the 1st partner’s unique id and in the listpage, you will find the 1st partner’s age. You will create 2 new variables in the loops below, “partuid” which is the 1st partner’s unique id and “partage” which is the 1st partner’s age (again for partner’s not living in the household at the date of the interview).

gen blank=.;

global listpuid
partners_id_1_97 partners_id_2_97 blank blank
partners_id_1_98 partners_id_2_98 partners_id_3_98 blank
partners_id_1_99 partners_id_2_99 blank blank
partners_id_1_00 partners_id_2_00 partners_id_3_00 partners_id_4_00
partners_id_1_01 partners_id_2_01 partners_id_3_01 partners_id_4_01
partners_id_1_02 partners_id_2_02 partners_id_3_02 blank
partners_id_1_03 partners_id_2_03 partners_id_3_03 blank
partners_id_1_04 partners_id_2_04 partners_id_3_04 blank
partners_id_1_05 partners_id_2_05 partners_id_3_05 partners_id_4_05
partners_id_1_06 partners_id_2_06 partners_id_3_06 blank;

global listpuid
partners_uid_1_97 partners_uid_2_97 blank blank
partners_uid_1_98 partners_uid_2_98 partners_uid_3_98 blank
partners_uid_1_99 partners_uid_2_99 blank blank
partners_uid_1_00 partners_uid_2_00 partners_uid_3_00 partners_uid_4_00
partners_uid_1_01 partners_uid_2_01 partners_uid_3_01 partners_uid_4_01
partners_uid_1_02 partners_uid_2_02 partners_uid_3_02 blank
partners_uid_1_03 partners_uid_2_03 partners_uid_3_03 blank
partners_uid_1_04 partners_uid_2_04 partners_uid_3_04 blank
partners_uid_1_05 partners_uid_2_05 partners_uid_3_05 partners_uid_4_05
partners_uid_1_06 partners_uid_2_06 partners_uid_3_06 blank;

global listpage
YMAR3200_01_97 YMAR3200_02_97 blank blank
YMAR3200_01_98 YMAR3200_02_98 YMAR3200_03_98 blank
YMAR3200_01_99 YMAR3200_02_99 blank blank
YMAR3200_01_00 YMAR3200_02_00 YMAR3200_03_00 YMAR3200_04_00
YMAR3200_01_01 YMAR3200_02_01 YMAR3200_03_01 YMAR3200_04_01
YMAR3200_01_02 YMAR3200_02_02 YMAR3200_03_02 blank
YMAR3200_01_03 YMAR3200_02_03 YMAR3200_03_03 blank
YMAR3200_01_04 YMAR3200_02_04 YMAR3200_03_04 blank
YMAR3200_01_05 YMAR3200_02_05 YMAR3200_03_05
YMAR3200_04_05
YMAR3200_01_06 YMAR3200_02_06 YMAR3200_03_06 blank;

gen partuid=.; gen partage=.;
gen l=0; gen k=0;

foreach pid of global listpid { ;
quietly replace l=l+1;

foreach puid of global listpuid {;
foreach page of global listpage { ;

** for partners no longer in hh, link to characteristics;
** for partners in hh, link to uid for hh roster **;
quietly replace k=k+1;
quietly replace partage=`page' if k>=startinvarlist &
k<=startinvarlist+4 & `pid’==firstpid;
quietly replace partuid=`puid' if k>=startinvarlist &
k<=startinvarlist+4 & `pid’==firstpid;

};
};
};


Step 6: For partners who were in the household use the unique id to find the partner on the household roster and link partner to his/her age

Thus far, you have found the age of the respondent’s first partner for partners with whom the respondent lived between rounds, but who were no longer living with the respondent at the date of the interview. The characteristics of partners who were living with the respondent at the time that the respondent was interviewed are available on the household roster for that round.

You’ll use the partner’s unique id to identify him or her on the household roster. To do this you’ll loop through the “hhuid’s” household unique id’s. There are up to 17 household members in some Round 1 households. That is the largest household size across rounds, so make the variable list is 10 rows (one for each round) by 17 columns (largest household size).

The sample code uses the “round” variable that you created in step 3 to find the round in which the partner is first reported by the respondent. In addition, we must check the household unique id’s for that round until we find the one that is the same as the partner’s unique id. At that same location in “listhhage”, you’ll find the 1st partner’s age.

global listhhuid HHI2UID01_97 HHI2UID02_97 HHI2UID03_97
HHI2UID04_97 HHI2UID05_97 HHI2UID06_97 HHI2UID07_97 HHI2UID08_97 HHI2UID09_97 HHI2UID10_97 HHI2UID11_97 HHI2UID12_97 HHI2UID13_97 HHI2UID14_97 HHI2UID15_97 HHI2UID16_97 HHI2UID17_97
HHIUID01_98 HHIUID02_98 HHIUID03_98 HHIUID04_98 HHIUID05_98 HHIUID06_98 HHIUID07_98 HHIUID08_98 HHIUID09_98 HHIUID10_98 HHIUID11_98 HHIUID12_98 HHIUID13_98 HHIUID14_98 blank blank blank
HHIUID01_99 HHIUID02_99 HHIUID03_99 HHIUID04_99 HHIUID05_99 HHIUID06_99 HHIUID07_99 HHIUID08_99 HHIUID09_99 HHIUID10_99 HHIUID11_99 HHIUID12_99 HHIUID13_99 HHIUID14_99 blank blank blank
HHIUID01_00 HHIUID02_00 HHIUID03_00 HHIUID04_00 HHIUID05_00 HHIUID06_00 HHIUID07_00 HHIUID08_00 HHIUID09_00 HHIUID10_00 HHIUID11_00 HHIUID12_00 HHIUID13_00 HHIUID14_00 blank blank blank
HHIUID01_01 HHIUID02_01 HHIUID03_01 HHIUID04_01 HHIUID05_01 HHIUID06_01 HHIUID07_01 HHIUID08_01 HHIUID09_01 HHIUID10_01 HHIUID11_01 HHIUID12_01 HHIUID13_01 HHIUID14_01 HHIUID15_01 HHIUID16_01 blank
HHIUID01_02 HHIUID02_02 HHIUID03_02 HHIUID04_02 HHIUID05_02 HHIUID06_02 HHIUID07_02 HHIUID08_02 HHIUID09_02 HHIUID10_02 HHIUID11_02 HHIUID12_02 HHIUID13_02 blank blank blank blank
HHIUID01_03 HHIUID02_03 HHIUID03_03 HHIUID04_03 HHIUID05_03 HHIUID06_03 HHIUID07_03 HHIUID08_03 HHIUID09_03 HHIUID10_03 HHIUID11_03 HHIUID12_03 HHIUID13_03 blank blank blank blank
HHIUID01_04 HHIUID02_04 HHIUID03_04 HHIUID04_04 HHIUID05_04 HHIUID06_04 HHIUID07_04 HHIUID08_04 HHIUID09_04 HHIUID10_04 HHIUID11_04 HHIUID12_04
blank blank blank blank blank
HHIUID01_05 HHIUID02_05 HHIUID03_05 HHIUID04_05 HHIUID05_05 HHIUID06_05 HHIUID07_05 HHIUID08_05 HHIUID09_05 HHIUID10_05 HHIUID11_05 HHIUID12_05 HHIUID13_05 HHIUID14_05 blank blank blank blank
HHIUID01_06 HHIUID02_06 HHIUID03_06 HHIUID04_06 HHIUID05_06 HHIUID06_06 HHIUID07_06 HHIUID08_06 HHIUID09_06 HHIUID10_06 HHIUID11_06 HHIUID12_06 HHIUID13_06 HHIUID14_06 blank blank blank;

global listhhage HHI2AGE01_97 HHI2AGE02_97 HHI2AGE03_97 HHI2AGE04_97 HHI2AGE05_97
HHI2AGE06_97 HHI2AGE07_97 HHI2AGE08_97 HHI2AGE09_97 HHI2AGE10_97 HHI2AGE11_97 HHI2AGE12_97 HHI2AGE13_97 HHI2AGE14_97 HHI2AGE15_97 HHI2AGE16_97 HHI2AGE17_97
HHIAGE01_98 HHIAGE02_98 HHIAGE03_98 HHIAGE04_98 HHIAGE05_98 HHIAGE06_98 HHIAGE07_98 HHIAGE08_98 HHIAGE09_98 HHIAGE10_98 HHIAGE11_98 HHIAGE12_98 HHIAGE13_98 HHIAGE14_98 blank blank blank
HHIAGE01_99 HHIAGE02_99 HHIAGE03_99 HHIAGE04_99 HHIAGE05_99 HHIAGE06_99 HHIAGE07_99 HHIAGE08_99 HHIAGE09_99 HHIAGE10_99 HHIAGE11_99 HHIAGE12_99 HHIAGE13_99 HHIAGE14_99 blank blank blank
HHIAGE01_00 HHIAGE02_00 HHIAGE03_00 HHIAGE04_00 HHIAGE05_00 HHIAGE06_00 HHIAGE07_00 HHIAGE08_00 HHIAGE09_00 HHIAGE10_00 HHIAGE11_00 HHIAGE12_00 HHIAGE13_00 HHIAGE14_00 blank blank blank
HHIAGE01_01 HHIAGE02_01 HHIAGE03_01 HHIAGE04_01 HHIAGE05_01 HHIAGE06_01 HHIAGE07_01 HHIAGE08_01 HHIAGE09_01 HHIAGE10_01 HHIAGE11_01 HHIAGE12_01 HHIAGE13_01 HHIAGE14_01 HHIAGE15_01 HHIAGE16_01 blank
HHIAGE01_02 HHIAGE02_02 HHIAGE03_02 HHIAGE04_02 HHIAGE05_02 HHIAGE06_02 HHIAGE07_02 HHIAGE08_02 HHIAGE09_02 HHIAGE10_02 HHIAGE11_02 HHIAGE12_02 HHIAGE13_02 blank blank blank blank
HHIAGE01_03 HHIAGE02_03 HHIAGE03_03 HHIAGE04_03 HHIAGE05_03 HHIAGE06_03 HHIAGE07_03 HHIAGE08_03 HHIAGE09_03 HHIAGE10_03 HHIAGE11_03 HHIAGE12_03 HHIAGE13_03 blank blank blank blank
HHIAGE01_04 HHIAGE02_04 HHIAGE03_04 HHIAGE04_04 HHIAGE05_04 HHIAGE06_04 HHIAGE07_04 HHIAGE08_04 HHIAGE09_04 HHIAGE10_04 HHIAGE11_04 HHIAGE12_04
blank blank blank blank blank
HHIAGE01_05 HHIAGE02_05 HHIAGE03_05 HHIAGE04_05 HHIAGE05_05 HHIAGE06_05 HHIAGE07_05 HHIAGE08_05 HHIAGE09_05 HHIAGE10_05 HHIAGE11_05 HHIAGE12_05 HHIAGE13_05 blank blank blank blank
HHIAGE01_06 HHIAGE02_06 HHIAGE03_06 HHIAGE04_06 HHIAGE05_06 HHIAGE06_06 HHIAGE07_06 HHIAGE08_06 HHIAGE09_06 HHIAGE10_06 HHIAGE11_06 HHIAGE12_06 HHIAGE13_06 HHIAGE14_06 blank blank blank;

replace l=0; gen countround=.;
foreach hhuid of global listhhuid { ;

quietly replace k=0;
quietly replace l=l+1;

foreach hhage of global listhhage { ;

quietly replace k=k+1;
quietly replace countround=int(l/18)+1;
quietly replace partage=`hhage' if partuid > 0 & partuid == `hhuid' & partage==. & k==l & int(l/18)+1 == round;

};
};


Step 7: For non-resident partners from prior to the date of the NLSY97 Round 1 interview, get age from the non-resident roster in Round 1

There is one last possible location to find the age of the respondent’s first partner—on the Round 1 non-resident roster.

The structure is very similar to that encountered when we used the partner roster or the household roster above. We create 2 macros: (1) contains the unique ids of all key non-residents that get rostered onto the Round 1 non-resident roster, “listnruid” and (2) contains the age of those on the non-resident roster, “listnrage”.

Because we are only checking the Round 1 non-resident roster, our lists have only one row. The longest non-resident roster in Round 1 has 23 people on it, thus we have 23 variables in the NLSY97 that tell unique id, and 23 for age (and other characteristics) of the members of the non-resident roster. Consequently, the variable lists used here have 23 elements.

If the variable we made for the 1st partner’s unique id (partuid) has a value between 200 and 300, then that partner is on the Round 1 non-resident roster. The first line of the sample code below checks this condition and only executes the lines that loop through the elements in the array if the 1st partner is on the Round 1 non-resident roster. The sample code then checks to find the 1st partner’s unique id, and if found fills in the variable “partage” with the corresponding age in the variable list “nrage”.

global listnruid NONHHIUID_01-NONHHIUID_23;
global listnrage NONHHIAGE_01-NONHHIAGE_23;

foreach nruid of global listnruid { ;
foreach nrage of global listnrage { ;

gen partage=`nrage' if partuid > 200 & partuid < 300 & partuid==`nruid' & partage < 0;

};
};


Return to the main tutorial to review the output and additional information.