Marital Status and Marital/Cohabitation History - Appendix 3

National Longitudinal Survey of Youth - 1997 Cohort

Marital Status and Marital/Cohabitation History - Appendix 3

Variables Created

  • CV_MARSTAT (marstat)--marital status as of interview date (10 categories coded)
  • CV_MARSTAT_COLLAPSED (cmarstat)--marital status as of interview date (5 categories coded)
  • CVC_FIRST_COHAB_DATE~M (cohm), CV_FIRST_COHAB_DATE~Y (cohy)--date of first cohabitation
  • CVC_FIRST_MARRY_DATE~M (marm), CV_FIRST_MARRY_DATE~Y (mary)--date of first marriage
  • CVC_FIRST_COHAB_MONTH (cohcm)--date of first cohabitation in continuous month format
  • CVC_FIRST_MARRY_MONTH (marcm)--date of first marriage in continuous month format
  • CVC_FIRST_MARRY_END_DATE~M (divorceM), CVC_FIRST_MARRY_END_DATE~Y (divorceY)--date of end of first marriage
  • CVC_FIRST_MARRY_END_MONTH (divor_CM)--date of end of first marriage in continuous month formart
  • CVC_FIRST_MARRY_END (end_mar)--reason first marriage ended
  • CVC_COHAB_TTL (och_ttl)--total number of cohabitations
  • CVC_MARRIAGES_TTL (mar_ttl)--total number of marriages

This program creates two variables that describe marital status/cohabitation status as of the interview date for respondents age 16 and older. Other respondents are valid skips (-4). Note that later partners take precedence over earlier partners.

The program also creates variables that provide the beginning and end dates of the youth's first marriage and/or cohabitation in both a continuous month scheme and as actual dates (for more information on the continuous month scheme, see Appendix 7), as well as the reason the first marriage ended. Summary variables count the total number of marriages and cohabitations for each youth. If a respondent is cohabiting and then marries it is considered both a cohabitation and a marriage. If someone refuses or doesn't know the full date of their marriage or cohabitation, then the spell is counted in the total variables and the date variables are coded -1 or -2 as applicable.

Variables Used

/*Variable Names in the Program           Variable Names on the Gator*/

  M620                                    'YMAR-620_2010'n
  M630                                    'YMAR-630_2010'n
  M640                                    'YMAR-640_2010'n
  M650                                    'YMAR-650_2010'n
  M714J1                                  'YMAR-714J.01_2010'n
  M714J2                                  'YMAR-714J.02_2010'n
  M714JB1M                                'YMAR-714JB.01~M_2010'n
  M714JB1Y                                'YMAR-714JB.01~Y_2010'n
  M714JB2M                                'YMAR-714JB.02~M_2010'n
  M714JB2Y                                'YMAR-714JB.02~Y_2010'n
  M716J1                                  'YMAR-716J.01_2010'n
  M716J2                                  'YMAR-716J.02_2010'n
  M716J3                                  'YMAR-716J.03_2010'n
  M716J5                                  'YMAR-716J.05_2010'n
  M716JB1M                                'YMAR-716JB.01~M_2010'n
  M716JB1Y                                'YMAR-716JB.01~Y_2010'n
  M716JB2M                                'YMAR-716JB.02~M_2010'n
  M716JB2Y                                'YMAR-716JB.02~Y_2010'n
  M716M1                                  'YMAR-716M.01_2010'n
  M716M2                                  'YMAR-716M.02_2010'n
  M716M3                                  'YMAR-716M.03_2010'n
  M716M4                                  'YMAR-716M.04_2010'n
  M716M6                                  'YMAR-716M.06_2010'n
  M7171                                   'YMAR-717.01_2010'n
  M7172                                   'YMAR-717.02_2010'n
  M7173                                   'YMAR-717.03_2010'n
  M735                                    'YMAR-735_2010'n
  M736                                    'YMAR-736_2010'n
  M740R                                   'YMAR-740R_2010'n
  M740RA                                  'YMAR-740RA_2010'n
  M751                                    'YMAR-751_2010'n
  M6400A1                                 'YMAR-6400A.01_2010'n
  M6400A2                                 'YMAR-6400A.02_2010'n
  M6400A3                                 'YMAR-6400A.03_2010'n
  M6400A4                                 'YMAR-6400A.04_2010'n
  M31001M                                 'YMAR-3100.01~M_2010'n
  M31001Y                                 'YMAR-3100.01~Y_2010'n
  M31002M                                 'YMAR-3100.02~M_2010'n
  M31002Y                                 'YMAR-3100.02~Y_2010'n
  M31003M                                 'YMAR-3100.03~M_2010'n
  M31003Y                                 'YMAR-3100.03~Y_2010'n
  M3100A1M                                'YMAR-3100A.01~M_2010'n
  M3100A1Y                                'YMAR-3100A.01~Y_2010'n
  M3100A2M                                'YMAR-3100A.02~M_2010'n
  M3100A2Y                                'YMAR-3100A.02~Y_2010'n
  M3100A4M                                'YMAR-3100A.04~M_2010'n
  M3100A4Y                                'YMAR-3100A.04~Y_2010'n
  M3100C1M                                'YMAR-3100C.01~M_2010'n
  M3100C1Y                                'YMAR-3100C.01~Y_2010'n
  M4350A1                                 'YMAR-4350A.01_2010'n
  M4350A2                                 'YMAR-4350A.02_2010'n
  M4350A4                                 'YMAR-4350A.04_2010'n
  M4360A1M                                'YMAR-4360A.01~M_2010'n
  M4360A1Y                                'YMAR-4360A.01~Y_2010'n
  M4370A1M                                'YMAR-4370A.01~M_2010'n
  M4370A1Y                                'YMAR-4370A.01~Y_2010'n
  M45001                                  'YMAR-4500.01_2010'n
  M45002                                  'YMAR-4500.02_2010'n
  M45003                                  'YMAR-4500.03_2010'n
  M46501                                  'YMAR-4650.01_2010'n
  M46502                                  'YMAR-4650.02_2010'n
  M46503                                  'YMAR-4650.03_2010'n
  M46551                                  'YMAR-4655.01_2010'n
  M46701                                  'YMAR-4670.01_2010'n
  M46702                                  'YMAR-4670.02_2010'n
  M47001                                  'YMAR-4700.01_2010'n
  M47002                                  'YMAR-4700.02_2010'n
  M47003                                  'YMAR-4700.03_2010'n
  M48001M                                 'YMAR-4800.01~M_2010'n
  M48001Y                                 'YMAR-4800.01~Y_2010'n
  M48002M                                 'YMAR-4800.02~M_2010'n
  M48002Y                                 'YMAR-4800.02~Y_2010'n
  M48003M                                 'YMAR-4800.03~M_2010'n
  M48003Y                                 'YMAR-4800.03~Y_2010'n
  M540011                                 'YMAR-5400.01.01_2010'n
  M540012                                 'YMAR-5400.01.02_2010'n
  M540013                                 'YMAR-5400.01.03_2010'n
  M540021                                 'YMAR-5400.02.01_2010'n
  M540022                                 'YMAR-5400.02.02_2010'n
  M560011M                                'YMAR-5600.01.01~M_2010'n
  M560011Y                                'YMAR-5600.01.01~Y_2010'n
  M560012M                                'YMAR-5600.01.02~M_2010'n
  M560012Y                                'YMAR-5600.01.02~Y_2010'n
  M560013M                                'YMAR-5600.01.03~M_2010'n
  M560013Y                                'YMAR-5600.01.03~Y_2010'n
  M560022M                                'YMAR-5600.02.02~M_2010'n
  M560022Y                                'YMAR-5600.02.02~Y_2010'n
  M570011M                                'YMAR-5700.01.01~M_2010'n
  M570011Y                                'YMAR-5700.01.01~Y_2010'n
  M570021M                                'YMAR-5700.02.01~M_2010'n
  M570021Y                                'YMAR-5700.02.01~Y_2010'n
  M63001                                  'YMAR-6300.01_2010'n
  M63002                                  'YMAR-6300.02_2010'n
  M63003                                  'YMAR-6300.03_2010'n
  M64001                                  'YMAR-6400.01_2010'n
  M64002                                  'YMAR-6400.02_2010'n
  M64003                                  'YMAR-6400.03_2010'n
  M700011M                                'YMAR-7000.01.01~M_2010'n
  M700011Y                                'YMAR-7000.01.01~Y_2010'n
  M700012M                                'YMAR-7000.01.02~M_2010'n
  M700012Y                                'YMAR-7000.01.02~Y_2010'n
  M700021M                                'YMAR-7000.02.01~M_2010'n
  M700021Y                                'YMAR-7000.02.01~Y_2010'n
  M730011                                 'YMAR-7300.01.01_2010'n
  M730021                                 'YMAR-7300.02.01_2010'n
  M730031                                 'YMAR-7300.03.01_2010'n
  M7900111                                'YMAR-7900.01.01.01_2010'n
  M7900112                                'YMAR-7900.01.01.02_2010'n
  M7900113                                'YMAR-7900.01.01.03_2010'n
  M7900211                                'YMAR-7900.02.01.01_2010'n
  M7900212                                'YMAR-7900.02.01.02_2010'n
  M8100111M                               'YMAR-8100.01.01.01~M_2010'n
  M8100111Y                               'YMAR-8100.01.01.01~Y_2010'n
  M8100112M                               'YMAR-8100.01.01.02~M_2010'n
  M8100112Y                               'YMAR-8100.01.01.02~Y_2010'n
  M8100113M                               'YMAR-8100.01.01.03~M_2010'n
  M8100113Y                               'YMAR-8100.01.01.03~Y_2010'n
  M8100212M                               'YMAR-8100.02.01.02~M_2010'n
  M8100212Y                               'YMAR-8100.02.01.02~Y_2010'n
  M8200111M                               'YMAR-8200.01.01.01~M_2010'n
  M8200111Y                               'YMAR-8200.01.01.01~Y_2010'n
  M8200112M                               'YMAR-8200.01.01.02~M_2010'n
  M8200112Y                               'YMAR-8200.01.01.02~Y_2010'n
  M8200211M                               'YMAR-8200.02.01.01~M_2010'n
  M8200211Y                               'YMAR-8200.02.01.01~Y_2010'n
  M8400111                                'YMAR-8400.01.01.01_2010'n
  M8400112                                'YMAR-8400.01.01.02_2010'n
  M8400113                                'YMAR-8400.01.01.03_2010'n
  M8400211                                'YMAR-8400.02.01.01_2010'n
  M8400212                                'YMAR-8400.02.01.02_2010'n
  M910011                                 'YMAR-9100.01.01_2010'n
  M910012                                 'YMAR-9100.01.02_2010'n
  M910021                                 'YMAR-9100.02.01_2010'n
  M920011M                                'YMAR-9200.01.01~M_2010'n
  M920011Y                                'YMAR-9200.01.01~Y_2010'n
  M920021M                                'YMAR-9200.02.01~M_2010'n
  M920021Y                                'YMAR-9200.02.01~Y_2010'n
  M930011                                 'YMAR-9300.01.01_2010'n
  M930012                                 'YMAR-9300.01.02_2010'n
  M930021                                 'YMAR-9300.02.01_2010'n
  M9620111                                'YMAR-9620.01.01.01_2010'n
  M9800111                                'YMAR-9800.01.01.01_2010'n
  M10000111M                              'YMAR-10000.01.01.01~M_2010'n
  M10000111Y                              'YMAR-10000.01.01.01~Y_2010'n
  M10010111                               'YMAR-10010.01.01.01_2010'n
  M10100111M                              'YMAR-10100.01.01.01~M_2010'n
  M10100111Y                              'YMAR-10100.01.01.01~Y_2010'n
  M10200111                               'YMAR-10200.01.01.01_2010'n
  M1080011                                'YMAR-10800.01.01_2010'n
  M1080021                                'YMAR-10800.02.01_2010'n
  M775                                    'YMAR-10900.01.01_2010'n
  M776                                    'YMAR-10900.02.01_2010'n
  M114001                                 'YMAR-11400.01_2010'n
  M114002                                 'YMAR-11400.02_2010'n
  M114003                                 'YMAR-11400.03_2010'n
  M117001M                                'YMAR-11700.01~M_2010'n
  M117001Y                                'YMAR-11700.01~Y_2010'n
  M117002M                                'YMAR-11700.02~M_2010'n
  M117002Y                                'YMAR-11700.02~Y_2010'n
  M117003M                                'YMAR-11700.03~M_2010'n
  M117003Y                                'YMAR-11700.03~Y_2010'n
  M13125                                  'YMAR-13125_2010'n
  M13150M                                 'YMAR-13150~M_2010'n
  M13150Y                                 'YMAR-13150~Y_2010'n
  M13200                                  'YMAR-13200_2010'n
  M13225                                  'YMAR-13225_2010'n
  M13250M                                 'YMAR-13250~M_2010'n
  M13250Y                                 'YMAR-13250~Y_2010'n
  PUBID                                   'PUBID_2010'n
  P_ST1                                   'PARTNERS_STATUS.01_2010'n
  P_ST2                                   'PARTNERS_STATUS.02_2010'n
  P_ST3                                   'PARTNERS_STATUS.03_2010'n
  P1                                      'PARTNERS_ID.01_2010'n
  P2                                      'PARTNERS_ID.02_2010'n
  P3;                                     'PARTNERS_ID.03_2010'n
  BDATE_M                                 KEY!BDATE_M_1997
  BDATE_Y                                 KEY!BDATE_Y_1997
  P1R1                                    PARTNERS_ID.01_1997
  P2R1                                    PARTNERS_ID.02_1997
  P1R3                                    PARTNERS_ID.01_1999
  P2R3                                    PARTNERS_ID.02_1999
  P1R2                                    PARTNERS_ID.01_1998
  P2R2                                    PARTNERS_ID.02_1998
  P3R2                                    PARTNERS_ID.03_1998
  P1R4                                    PARTNERS_ID.01_2000
  P2R4                                    PARTNERS_ID.02_2000
  P3R4                                    PARTNERS_ID.03_2000
  P4R4                                    PARTNERS_ID.04_2000
  P1R5                                    PARTNERS_ID.01_2001
  P2R5                                    PARTNERS_ID.02_2001
  P3R5                                    PARTNERS_ID.03_2001
  P4R5                                    PARTNERS_ID.04_2001
  P1R6                                    PARTNERS_ID.01_2002
  P2R6                                    PARTNERS_ID.02_2002
  P3R6                                    PARTNERS_ID.03_2002
  P1R7                                    PARTNERS_ID.01_2003
  P2R7                                    PARTNERS_ID.02_2003
  P3R7                                    PARTNERS_ID.03_2003
  P1R8                                    PARTNERS_ID.01_2004
  P2R8                                    PARTNERS_ID.02_2004
  P3R8                                    PARTNERS_ID.03_2004
  P1R9                                    PARTNERS_ID.01_2005
  P2R9                                    PARTNERS_ID.02_2005
  P3R9                                    PARTNERS_ID.03_2005
  P4R9                                    PARTNERS_ID.04_2005
  P1R10                                   PARTNERS_ID.01_2006
  P2R10                                   PARTNERS_ID.02_2006
  P3R10                                   PARTNERS_ID.03_2006
  P1R11                                   PARTNERS_ID.01_2007
  P2R11                                   PARTNERS_ID.02_2007
  P3R11                                   PARTNERS_ID.03_2007
  P1R12                                   PARTNERS_ID.01_2008
  P2R12                                   PARTNERS_ID.02_2008
  P3R12                                   PARTNERS_ID.03_2008
  P1R13                                   PARTNERS_ID.01_2009
  P2R13                                   PARTNERS_ID.02_2009
  P3R13                                   PARTNERS_ID.03_2009
  FCOH_MR1                                CV_FIRST_COHAB_DATE 1997
  FCOH_YR1                                CV_FIRST_COHAB_DATE 1997
  FCOHCMR1                                CV_FIRST_COHAB_MONTH 1997
  FMAR_MR1                                CV_FIRST_MARRY_DATE 1997
  FMAR_YR1                                CV_FIRST_MARRY_DATE 1997
  FMARCMR1                                CV_FIRST_MARRY_MONTH 1997
  int_cmr1                                CV_INTERVIEW_CMONTH 1997
  INT_DR1                                 CV_INTERVIEW_DATE 1997
  INT_MR1                                 CV_INTERVIEW_DATE 1997
  INT_YR1                                 CV_INTERVIEW_DATE 1997
  MARSTATR1                               CV_MARSTAT 1997
  CMARSTAR1                               CV_MARSTAT_COLLAPSED 1997
  COH_TTLR1                               CV_COHAB_TTL 1997
  MAR_TTLR1                               CV_MARRIAGES_TTL 1997
  SAMPLE_TYPE                             CV_SAMPLE_TYPE 1997
  FCOH_MR2                                CV_FIRST_COHAB_DATE 1998
  FCOH_YR2                                CV_FIRST_COHAB_DATE 1998
  FCOHCMR2                                CV_FIRST_COHAB_MONTH 1998
  FMAR_MR2                                CV_FIRST_MARRY_DATE 1998
  FMAR_YR2                                CV_FIRST_MARRY_DATE 1998
  FMARCMR2                                CV_FIRST_MARRY_MONTH 1998
  int_cmr2                                CV_INTERVIEW_CMONTH 1998
  INT_DR2                                 CV_INTERVIEW_DATE 1998
  INT_MR2                                 CV_INTERVIEW_DATE 1998
  INT_YR2                                 CV_INTERVIEW_DATE 1998
  MARSTATR2                               CV_MARSTAT 1998
  CMARSTAR2                               CV_MARSTAT_COLLAPSED 1998
  COH_TTLR2                               CV_COHAB_TTL 1998
  MAR_TTLR2                               CV_MARRIAGES_TTL 1998
  FCOH_MR3                                CV_FIRST_COHAB_DATE 1999
  FCOH_YR3                                CV_FIRST_COHAB_DATE 1999
  FCOHCMR3                                CV_FIRST_COHAB_MONTH 1999
  FMAR_MR3                                CV_FIRST_MARRY_DATE 1999
  FMAR_YR3                                CV_FIRST_MARRY_DATE 1999
  FMARCMR3                                CV_FIRST_MARRY_MONTH 1999
  int_cmr3                                CV_INTERVIEW_CMONTH 1999
  INT_DR3                                 CV_INTERVIEW_DATE 1999
  INT_MR3                                 CV_INTERVIEW_DATE 1999
  INT_YR3                                 CV_INTERVIEW_DATE 1999
  MARSTATR3                               CV_MARSTAT 1999
  CMARSTAR3                               CV_MARSTAT_COLLAPSED 1999
  COH_TTLR3                               CV_COHAB_TTL 1999
  MAR_TTLR3                               CV_MARRIAGES_TTL 1999
  FCOH_MR4                                CV_FIRST_COHAB_DATE 2000
  FCOH_YR4                                CV_FIRST_COHAB_DATE 2000
  FCOHCMR4                                CV_FIRST_COHAB_MONTH 2000
  FMAR_MR4                                CV_FIRST_MARRY_DATE 2000
  FMAR_YR4                                CV_FIRST_MARRY_DATE 2000
  FMARCMR4                                CV_FIRST_MARRY_MONTH 2000
  int_cmr4                                CV_INTERVIEW_CMONTH 2000
  INT_DR4                                 CV_INTERVIEW_DATE 2000
  INT_MR4                                 CV_INTERVIEW_DATE 2000
  INT_YR4                                 CV_INTERVIEW_DATE 2000
  MARSTATR4                               CV_MARSTAT 2000
  CMARSTAR4                               CV_MARSTAT_COLLAPSED 2000
  COH_TTLR4                               CV_COHAB_TTL 2000
  MAR_TTLR4                               CV_MARRIAGES_TTL 2000
  FCOH_MR5                                CV_FIRST_COHAB_DATE 2001
  FCOH_YR5                                CV_FIRST_COHAB_DATE 2001
  FCOHCMR5                                CV_FIRST_COHAB_MONTH 2001
  FMAR_MR5                                CV_FIRST_MARRY_DATE 2001
  FMAR_YR5                                CV_FIRST_MARRY_DATE 2001
  FMARCMR5                                CV_FIRST_MARRY_MONTH 2001
  int_cmr5                                CV_INTERVIEW_CMONTH 2001
  INT_DR5                                 CV_INTERVIEW_DATE 2001
  INT_MR5                                 CV_INTERVIEW_DATE 2001
  INT_YR5                                 CV_INTERVIEW_DATE 2001
  MARSTATR5                               CV_MARSTAT 2001
  CMARSTAR5                               CV_MARSTAT_COLLAPSED 2001
  COH_TTLR5                               CV_COHAB_TTL 2001
  MAR_TTLR5                               CV_MARRIAGES_TTL 2001
  FCOH_MR6                                CV_FIRST_COHAB_DATE 2002
  FCOH_YR6                                CV_FIRST_COHAB_DATE 2002
  FCOHCMR6                                CV_FIRST_COHAB_MONTH 2002
  FMAR_MR6                                CV_FIRST_MARRY_DATE 2002
  FMAR_YR6                                CV_FIRST_MARRY_DATE 2002
  FMARCMR6                                CV_FIRST_MARRY_MONTH 2002
  int_cmr6                                CV_INTERVIEW_CMONTH 2002
  INT_DR6                                 CV_INTERVIEW_DATE 2002
  INT_MR6                                 CV_INTERVIEW_DATE 2002
  INT_YR6                                 CV_INTERVIEW_DATE 2002
  MARSTATR6                               CV_MARSTAT 2002
  CMARSTAR6                               CV_MARSTAT_COLLAPSED 2002
  COH_TTLR6                               CV_COHAB_TTL 2002
  MAR_TTLR6                               CV_MARRIAGES_TTL 2002
  FCOH_MR7                                CV_FIRST_COHAB_DATE 2003
  FCOH_YR7                                CV_FIRST_COHAB_DATE 2003
  FCOHCMR7                                CV_FIRST_COHAB_MONTH 2003
  FMAR_MR7                                CV_FIRST_MARRY_DATE 2003
  FMAR_YR7                                CV_FIRST_MARRY_DATE 2003
  FMARCMR7                                CV_FIRST_MARRY_MONTH 2003
  int_cmr7                                CV_INTERVIEW_CMONTH 2003
  INT_DR7                                 CV_INTERVIEW_DATE 2003
  INT_MR7                                 CV_INTERVIEW_DATE 2003
  INT_YR7                                 CV_INTERVIEW_DATE 2003
  MARSTATR7                               CV_MARSTAT 2003
  CMARSTAR7                               CV_MARSTAT_COLLAPSED 2003
  COH_TTLR7                               CV_COHAB_TTL 2003
  MAR_TTLR7                               CV_MARRIAGES_TTL 2003
  FCOH_MR8                                CV_FIRST_COHAB_DATE 2004
  FCOH_YR8                                CV_FIRST_COHAB_DATE 2004
  FCOHCMR8                                CV_FIRST_COHAB_MONTH 2004
  FMAR_MR8                                CV_FIRST_MARRY_DATE 2004
  FMAR_YR8                                CV_FIRST_MARRY_DATE 2004
  FMARCMR8                                CV_FIRST_MARRY_MONTH 2004
  int_cmr8                                CV_INTERVIEW_CMONTH 2004
  INT_DR8                                 CV_INTERVIEW_DATE 2004
  INT_MR8                                 CV_INTERVIEW_DATE 2004
  INT_YR8                                 CV_INTERVIEW_DATE 2004
  MARSTATR8                               CV_MARSTAT 2004
  CMARSTAR8                               CV_MARSTAT_COLLAPSED 2004
  COH_TTLR8                               CV_COHAB_TTL 2004
  MAR_TTLR8                               CV_MARRIAGES_TTL 2004
  FCOH_MR9                                CV_FIRST_COHAB_DATE 2005
  FCOH_YR9                                CV_FIRST_COHAB_DATE 2005
  FCOHCMR9                                CV_FIRST_COHAB_MONTH 2005
  FMAR_MR9                                CV_FIRST_MARRY_DATE 2005
  FMAR_YR9                                CV_FIRST_MARRY_DATE 2005
  FMARCMR9                                CV_FIRST_MARRY_MONTH 2005
  int_cmr9                                CV_INTERVIEW_CMONTH 2005
  INT_DR9                                 CV_INTERVIEW_DATE 2005
  INT_MR9                                 CV_INTERVIEW_DATE 2005
  INT_YR9                                 CV_INTERVIEW_DATE 2005
  MARSTATR9                               CV_MARSTAT 2005;
  CMARSTAR9                               CV_MARSTAT_COLLAPSED 2005
  COH_TTLR9                               CV_COHAB_TTL 2005
  MAR_TTLR9                               CV_MARRIAGES_TTL 20005
  FCOH_MR10                               CV_FIRST_COHAB_DATE 2006
  FCOH_YR10                               CV_FIRST_COHAB_DATE 2006
  FCOHCMR10                               CV_FIRST_COHAB_MONTH 2006
  FMAR_MR10                               CV_FIRST_MARRY_DATE 2006
  FMAR_YR10                               CV_FIRST_MARRY_DATE 2006
  FMARCMR10                               CV_FIRST_MARRY_MONTH 2006
  int_cmr10                               CV_INTERVIEW_CMONTH 2006
  INT_DR10                                CV_INTERVIEW_DATE 2006
  INT_MR10                                CV_INTERVIEW_DATE 2006
  INT_YR10                                CV_INTERVIEW_DATE 2006
  MARSTATR10                              CV_MARSTAT 2006
  CMARSTAR10                              CV_MARSTAT_COLLAPSED 2006
  COH_TTLR10                              CV_COHAB_TTL 2006
  MAR_TTLR10                              CV_MARRIAGES_TTL 2006
  COH_MR11                                CV_FIRST_COHAB_DATE 2007
  FCOH_YR11                               CV_FIRST_COHAB_DATE 2007
  FCOHCMR11                               CV_FIRST_COHAB_MONTH 2007
  FMAR_MR11                               CV_FIRST_MARRY_DATE 2007
  FMAR_YR11                               CV_FIRST_MARRY_DATE 2007
  FMARCMR11                               CV_FIRST_MARRY_MONTH 2007
  int_cmR11                               CV_INTERVIEW_CMONTH 2007
  INT_DR11                                CV_INTERVIEW_DATE 2007
  INT_MR11                                CV_INTERVIEW_DATE 2007
  INT_YR11                                CV_INTERVIEW_DATE 2007
  MARSTATR11                              CV_MARSTAT 2007
  CMARSTAR11                              CV_MARSTAT_COLLAPSED 2007
  COH_TTLR11                              CV_COHAB_TTL 2007
  MAR_TTLR11                              CV_MARRIAGES_TTL 2007
  end_marR12                              CVC_FIRST_MARRY_END 2007
  divo_MR12                               CVC_FIRST_MARRY_END_DATE~M 2007
  divo_YR12                               CVC_FIRST_MARRY_END_DATE~Y 2007
  COH_MR12                                CVC_FIRST_COHAB~DATE 2008
  FCOH_YR12                               CVC_FIRST_COHAB~DATE 2008
  FCOHCMR12                               CVC_FIRST_COHAB_MONTH 2008
  FMAR_MR12                               CVC_FIRST_MARRY~DATE 2008
  FMAR_YR12                               CVC_FIRST_MARRY~DATE 2008
  FMARCMR12                               CVC_FIRST_MARRY_MONTH 2008
  int_cmR12                               CVC_INTERVIEW_CMONTH 2008
  INT_DR12                                CV_INTERVIEW_DATE 2008
  INT_MR12                                CV_INTERVIEW_DATE 2008
  INT_YR12                                CV_INTERVIEW_DATE 2008
  MARSTATR12                              CV_MARSTAT 2008
  CMARSTAR12                              CV_MARSTAT_COLLAPSED 2008
  COH_TTLR12                              CV_COHAB_TTL 2008
  MAR_TTLR12                              CV_MARRIAGES_TTL 2008
  end_marR12                              CVC_FIRST_MARRY_END 2008
  divo_MR12                               CVC_FIRST_MARRY_END_DATE~M 2008
  divo_YR12                               CVC_FIRST_MARRY_END_DATE~Y 2008
  divor_CM                                CVC_first_divorce_month 2008
  COH_MR13                                CVC_FIRST_COHAB~DATE 2009
  FCOH_YR13                               CVC_FIRST_COHAB~DATE 2009
  FCOHCMR13                               CVC_FIRST_COHAB_MONTH 2009
  FMAR_MR13                               CVC_FIRST_MARRY~DATE 2009
  FMAR_YR13                               CVC_FIRST_MARRY~DATE 2009
  FMARCMR13                               CVC_FIRST_MARRY_MONTH 2009
  int_cmR13                               CVC_INTERVIEW_CMONTH 2009
  INT_DR13                                CV_INTERVIEW_DATE 2009
  INT_MR13                                CV_INTERVIEW_DATE 2009
  INT_YR13                                CV_INTERVIEW_DATE 2009
  MARSTATR13                              CV_MARSTAT 2009
  CMARSTAR13                              CV_MARSTAT_COLLAPSED 2009
  COH_TTLR13                              CV_COHAB_TTL 2009
  MAR_TTLR13                              CV_MARRIAGES_TTL 2009
  end_marR13                              CVC_FIRST_MARRY_END 2009
  divo_MR13                               CVC_FIRST_MARRY_END_DATE~M 2009
  divo_YR13                               CVC_FIRST_MARRY_END_DATE~Y 2009
  divor_CM                                CVC_first_divorce_month 2009
  M620R1                                  YMAR-620_1998
  M620R3                                  YMAR-620_1999
  M620R4                                  YMAR-620_2000
  M620R5                                  YMAR-620_2001
  M620R6                                  YMAR-620_2002
  M620R7                                  YMAR-620_2003
  M620R8                                  YMAR-620_2004
  M620R9                                  YMAR-620_2005
  M620R10                                 YMAR-620_2006
  M620R11                                 YMAR-620_2007
  M620R12                                 YMAR-620_2008
  M620R13                                 YMAR-620_2009

SAS Code for Variable Creation

 if pubid in (8342 8343 ) then do;
   int_y=-5;
   int_m=-5;
 end;

if pubid= 159 then do;
   M8100111M =-4;
   M8100111Y =-4;
   m7900111=-4;
end;

if pubid=5225 then m620=0; /* never married */

if pubid=51 then do;/*  missing marriage data */
  m31001y=-2;
  m31001m=-2;
  m45001=1;

  m48001m=m8100113m;
  m48001y=m8100113y;
  m7900112=-4;
  m7900113=-4;
  m47001=0;
  m46701=0;
 end;

if pubid= 3669 then m45002=0;  /* partner 1401 is R's partner */
if pubid = 2895 then do;  /* delete first loop */
m3100c1y=-4;
m3100c1m=-4;
m45001=-4;
m48001y=-4;
m48001m=-4;
p1=p2;
p2=-4;
m45001=1;
m46701=1;
m46702=-4;
end;

if pubid= 7472 then do;
m48001m=11;
m48001y=2009;
end;

if pubid=7984 then m540011=-4;  /* never married */

if pubid=8563 then do;
 m48003m=-4;
 m48003y=-4;
 end;
if pubid=8088 then  M31002M=12;
if pubid=5324 then do;
p2=-4;
m48002m=-4;
m48002y=-4;
end;

if pubid=7758 then do;  /*  DIVORCE date is early then marriage data code as -2*/
M4360A1M =-2;
M4360A1Y=-2;
sid=1201;
end;

/*double loops */
if pubid in (3434 4998 5015 8566) then do;
   m31002m=-4;
   m31002y=-4;
   m45002=-4;
   M47002=-4;
end;

/* no partners */
if pubid=7111 then do;
 m31001m=-4;
 m31001y=-4;
 m45001=-4;
 M47001=-4;
end;

/*  NEVER MARRIED   */
if pubid in (803, 1589, 6576,5558 ,6830)  then do;
m48001m=m8100111m;
m48001y=m8100111y;
m8100111m=-4;
m8100111y=-4;
m7900111=-4;
m46701=0;
M560011M =-4;
M560011Y=-4;
end;

if pubid  =7474 then do;   /*  ask marriage data  ????  */
m48001m=m560011m;
m48001y=m560011y;
m560011m=-4;
m560011y=-4;
end;

/* divorced no marriaeg data*/
if pubid in (3220, 4048,4546,5201 ) then do;
m45001=1;
m31001m=-1;
m31001y=-1;
end;

if pubid= 4546 then do;
m48001m=m560011m;
m48001y=m560011y;
end;

if pubid in (5201 ) then do;
m48001m=m48001m+1;
end;

if pubid= 8346 then do;
p1=p3;
p3=-4;
m31001m=M31003M;
m31001y=M31003Y;
M31003M=-4;
M31003Y=-4;
m47001=m47003;
M114001 =-4;
M117001m=-4;
M117001Y=-4;
end;

if pubid=6575 then do;
m114002=m7900212;
m117002m=m8100212m;
m117002y=m8100212y;
end;

if pubid=5378 then do;   /* double loops */
m46701=1;
m46702=-4;
end;

if pubid= 8858 then do;   /* double loops */
 m46701=1;
m46702=-4;
end;

 /* partner variables is missing  and bad divorce date  Ymar716JB*/
if pubid=7402 then do;
m716JB1m=-3;
m716jb1y=-3;
end;

if pubid=2138 then do;/* missing cohabiting date */
m31001y=-2;
m31001m=-2;
end;

if pubid=7220 then m9800111=4;
if pubid=7218 then m48001y=-1; /* m48001y=1900*/

if pubid= 4052 then do;  /* double loops */
  m48002m=-4;
  m48002y=-4;
  m31002y=-4;
  m31002m=-4;
  m45001=1;
end;

if pubid= 4040 then do;  /* double loops */
   p1=p2;
   p2=-4;
   m31002m=-4;
   m31002y=-4;
   m48002n=-4;
   m48002y=-4;
   m45001=1;
   m46701=1;
   m46702=-4;
 end;

if pubid= 3154 then do; /* dual */
   m48001m=-4;
   m48001y=-4;
end;

if pubid= 6208  then do; /*dual */
   m48001y=2009;
end;

if pubid=563 then do;  /*  Divorced at R15,  They are still married  */
    m540011  = -4;
    m560011m = -4;
    m560011y = -4;
end;

if M3100C1m>-4 then do;
   m31001m=m3100C1m;
   m31001y=m3100C1y;
   M3100C1m=-4;
   M3100C1y=-4;
end;

if M3100C2m>-4 then do;
   m31002m=m3100C2m;
   m31002y=m3100C2y;
   M3100C2m=-4;
   M3100C2y=-4;
 end;

 %let n=13 ;
          array   MARSTATr(&n);  array  CMARSTAr(&n);
          array   mar_ttlr(&n);  array  coh_ttlr(&n);
          array   FMAR_Yr(&n) ;  array  FMAR_Mr(&n) ;   array  fmarcmr(&n);
          array   FCOH_Mr(&n) ;  array  FCOH_Yr(&n) ;   array  FCOHCMr(&n);
          array   int_mr(&n)  ;  array  int_yr(&n)  ;   array  int_cmr(&n);
             array m620r(&n);

 do i=1 to (&n);
          if int_cmr(i)>0 then do;
          dlicm=int_cmr(i);
          dlimarstat=MARSTATr(i);
          dlicmarstat=CMARSTAr(i);
          premar_ttl=mar_ttlr(i);
          precoh_ttl= coh_ttlr(i);
          dlimarm=FMAR_Mr(i);
          dlimary= FMAR_Yr(i);
          dlimarcm= fmarcmr(i);
          dlicohm= FCOH_Mr(i);
          dlicohy =FCOH_Yr(i);
          dlicohcm =FCOHCMr(i);
          dliym=int_yr(i)*100+int_mr(i);
          dlim620=m620r(i);
          mardli=MARSTATr(i);
      end;
   end;
 drop i;

 do i=2 to (&n);
       if FCOHCMr(i-1)=-3 & FCOHCMr(i)>0 & FCOHCMr(i)>int_cmr(i-1)
       then do;
       FCOHCMr(i)=FCOHCMr(i-1);
       FCOH_Mr(i)=FCOH_Mr(i-1);
       FCOH_Yr(i)=FCOH_Yr(i-1);
    end;
 end;

do i=2 to (&n);
    if FMARCMr(i-1)=-3 & FMARCMr(i)>0 & FMARCMr(i)>int_cmr(i-1)
    then do;
    FMARCMr(i)=FMARCMr(i-1);
    FMAR_Mr(i)=FMAR_Mr(i-1);
    FMAR_Yr(i)=FMAR_Yr(i-1);
 end;
end;
 if precoh_ttl<-3  then  precoh_ttl=0;
 if premar_ttl<-3  then  premar_ttl=0;
 if bdate_y>0 & bdate_m>0 then b14cm=(bdate_y+14-1980)*12+bdate_m;
         start=dlicm+1;

 if int_y >0 & int_m >0  then do;
      iym=int_y*100+int_m;
        doicm=(int_y-1980)*12+int_m;
       end;
      else if int_y = -5  then do;
     doicm=-5;
 end;

if m13150y>0 & m13150m>0 then m13150cm=(m13150y -1980)*12 +m13150m;
if m13250y>0 & m13250m>0 then m13250cm=(m13250y -1980)*12 +m13250m;
if m13150cm>dlicm  then do;
   m7900111=1;
   m8200111m= m13150m;
   m8200111y= m13150y;
end;

  /* This array for first divo_ date */

array m4800m    (i) m48001m  m48002m   m48003m  m48004m ;
array m4800y    (i) m48001y  m48002y   m48003y  m48004y;
array m4800cm   (i) m48001cm m48002cm  m48003cm m48004cm;
array m3100m    (i) m31001m  m31002m   m31003m  m31004m;
array m3100y    (i) m31001y  m31002y   m31003y  m31004y;
array m3100cm   (i) m31001cm m31002cm  m31003cm m31004cm;

  flag4800=0;
  do i=1 to 4;
if m4800m >0 & m4800y>0 then do;
    M4800cm= (M4800y-1980)*12+m4800m;
     if 0<M4800cm<=start then flag4800=1;/* ok */

   end;
if m3100m >0 & m3100y>0 then do;
       M3100cm= (M3100y-1980)*12+m3100m;
       if m3100cm<=dlicm then flag3100=1;  /* ok*/
   end;
end;

 if precoh_ttl<-3  then  precoh_ttl=0;
 if premar_ttl<-3  then  premar_ttl=0;

/* Partner match, matching Round 12 partner to previous(round 1-11) partners */

 array par{4} p1-p4;

 array partner {4, 13} p1r1-p1R13 p2r1-p2R13 p3r1-p3R13 p4r1-p4R13;
 array Hspouse13 {13} spouse1-spouse13;
 array HpartneR13 {13} partner1-partneR13;
 array dlipar {4,13} p1r1-p1R13 p2r1-p2R13 p3r1-p3R13 p4r1-p4R13 ; /* dli partner */

flagp=0;
  do t=1 to 4;
    do i=1 to 4;
       do j=1 to 13;
           if par(t)=partner{i,j}& partner{i,j}>0
           then flagp=1;
        end;
    end;
end;

  /* set up arrays for R12  & R13 partner & spouse*/      /*  Partner & spouse arrays */

  array R13mars  (l) R13mars001-R13mars378;
  array R13co    (l) R13co001-R13co378;
  array R13link  (l) R13link001-R13link378;
  array r14pt    (l) r14pt001-r14pt378;
  array r14sp    (l) r14sp001-r14sp378;

  /* set up Mar arrays for each partner in four period*/
  array maf     (l) maf001-maf378;
  array mas     (l) mas001-mas378;
  array mat     (l) mat001-mat378;
  array mafour  (l) mafour001-mafour378;

  array mbf     (l) mbf001-mbf378;
  array mbs     (l) mbs001-mbs378;
  array mbt     (l) mbt001-mbt378;
  array mbfour  (l) mbfour001-mbfour378;

  array mcf     (l) mcf001-mcf378;
  array mcs     (l) mcs001-mcs378;
  array mct     (l) mct001-mct378;
  array mcfour  (l) mcfour001-mcfour378;

  array mdf     (l) mdf001-mdf378;
  array mds     (l) mds001-mds378;
  array mdt     (l) mdt001-mdt378;
  array mdfour  (l) mdfour001-mdfour378;

  /* array for partner a in first sec third & fourth period*/
  array maa     (l) maa001-maa378;
  array mbb     (l) mbb001-mbb378;
  array mcc     (l) mcc001-mcc378;
  array mdd     (l) mdd001-mdd378;

  /* set up arrays for mar total*/

  array mal (l) mal001-mal378;

  /* set up cohabition arrays for each partner in four period*/

  array cohaf    (l) cohaf001-cohaf378;
  array cohas    (l) cohas001-cohas378;
  array cohat    (l) cohat001-cohat378;
  array cohafour (l) cohafour001-cohafour378;

  array cohbf    (l) cohbf001-cohbf378;
  array cohbs    (l) cohbs001-cohbs378;
  array cohbt    (l) cohbt001-cohbt378;
  array cohbfour (l) cohbfour001-cohbfour378;

  array cohcf    (l) cohcf001-cohcf378;
  array cohcs    (l) cohcs001-cohcs378;
  array cohct    (l) cohct001-cohct378;
  array cohcfour (l) cohcfour001-cohcfour378;

  array cohdf    (l) cohdf001-cohdf378;
  array cohds    (l) cohds001-cohds378;
  array cohdt    (l) cohdt001-cohdt378;
  array cohdfour (l) cohdfour001-cohdfour378;

  array cohaa    (l)  cohaa001-cohaa378;
  array cohbb    (l)  cohbb001-cohbb378;
  array cohcc    (l)  cohcc001-cohcc378;
  array cohdd    (l)  cohdd001-cohdd378;

  /*cohabition totla*/

  array cohal   (l)   cohal001-cohal378;
  /*arrays for R12 event history */

  array mars    (l)   mars001-mars378;
  array cohh    (l)   cohh001-cohh378;
  array link    (l)   link001-link378;
  array dual    (l)   dual001-dual378;

   do l=start to 378;

        cohal=0;
        cohaf=0;     cohas=0;      cohat=0;      cohafour=0;
        cohbf=0;     cohbs=0;      cohbt=0;      cohbfour=0;
        cohcf=0;     cohcs=0;      cohct=0;      cohcfour=0;
        cohdf=0;     cohds=0;      cohdt=0;      cohdfour=0;
        mal=0  ;
        maf=0  ;     mas=0  ;      mat=0 ;       mafour=0  ;
        mbf=0  ;     mbs=0  ;      mbt=0 ;       mbfour=0  ;
        mcf=0  ;     mcs=0  ;      mct=0 ;       mcfour=0  ;
        mdf=0  ;     mds=0  ;      mdt=0 ;       mdfour=0  ;

  end;

  /* year start cohabitating*/

    array ysca  (t) M31001Y M700011Y M700012Y M700013Y;
    array yscb  (t) M31002Y M700021Y  M700022Y yscb4;
    array yscc  (t) M31003Y M700031Y yscc3 yscc4;
    array yscd  (t) M31004Y yscd2 yscd3 yscd4;

    array msca  (t) M31001M M700011M M700012M M700013M;
    array mscb  (t) M31002M M700021M M700022M  mscb4;
    array mscc  (t) M31003M M700031M  mscb3 mscb4;
    array mscd  (t) M31004M mscd2 mscd3 mscd4;
    array ysc   (p) ysca  yscb  yscc yscd;
    array msc   (p) msca  mscb  mscc mscd;

    array ycoa  (t) M31001Y M700011Y M700012Y M700013Y;  /*ycoa2 ycoa3 ycoa4; */
    array ycob  (t) M31002Y M700021Y  M700022Y yscb4;/*yscb2 yscb3 yscb4; */
    array ycoc  (t) M31003Y M700031Y yscc3 yscc4; /*yscc2 yscc3 yscc4;  */
    array ycod  (t) M31004Y ycod2 ycod3 ycod4;

    array mcoa  (t) M31001M M700011M M700012M M700013M;/*mcoa2 mcoa3 mcoa4; */
    array mcob  (t) M31002M M700021M M700022M mscb4; /*mcob2 mcob3 mcob4; */
    array mcoc  (t) M31003M M700031M  mscb3 mscb4; /*mcoc2 mcoc3 mcoc4; */
    array mcod  (t) M31004M mcod2 mcod3 mcod4;

    array yco   (p) ycoa  ycob  ycoc ycod;
    array mco   (p) mcoa  mcob  mcoc mcod;

    array ymcoa (t) ymcoa1  ymcoa2  ymcoa3 ymcoa4;
    array ymcob (t) ymcob1  ymcob2  ymcob3 ymcob4;
    array ymcoc (t) ymcoc1  ymcoc2  ymcoc3 ymcoc4;
    array ymcod (t) ymcod1  ymcod2  ymcod3 ymcod4;

    array ymco (p) ymcoa ymcob ymcoc ymcod;

  /** R11 added  */

    array yspa  (t) M3100A1Y  yspa2   yspa3  yspa4;
    array yspb  (t) M3100A2Y  yspb2   yspb3  yspb4;
    array yspc  (t) M3100A3Y  yspc2   yspc3  yspc4;
    array yspd  (t) yspd1     yspd2   yspd3  yspd4;
    array mspa  (t) M3100A1M mspa2 mspa3 mspa4;
    array mspb  (t) M3100A2M mspb2 mspb3 mspb4;
    array mspc  (t) M3100A3M mspc2 mspc3 mspc4;
    array mspd  (t) mspd1 mspd2 mspd3 mspd4;
    array ysp   (p) yspa  yspb  yspc yspd;
    array msp   (p) mspa  mspb  mspc mspd;
    array ymspa (t) ymspa1 ymspa2 ymspa3 ymspa4;
    array ymspb (t) ymspb1 ymspb2 ymspb3 ymspb4;
    array ymspc (t) ymspc1 ymspc2 ymspc3 ymspc4;
    array ymspd (t) ymspd1 ymspd2 ymspd3 ymspd4;

       array ymsp  (p) ymspa ymspb ymspc ymspd;

   /*R12 added*/

    array yBsca  (t) M3100C1Y yBscb2 yBsca3 yBsca4;
    array yBscb  (t) M3100C2Y yBscb2 yBscb3 yBscb4;
    array yBscc  (t) M3100C3Y yBscc2 yBscc3 yBscc4;
    array yBscd  (t) yBscd1 yBscd2 yBscd3 yBscd4;
    array mBsca  (t) M31001CM mBsca2 mBsca3 mBsca4;
    array mBscb  (t) M31002CM mBscb2 mBscb3 mBscb4;
    array mBscc  (t) M31003CM mBscc2 mBscc3 mBscc4;
    array mBscd  (t) mBsca1 mBscd2 mBscd3 mBscd4;
    array yBsc   (p) yBsca  yBscb  yBscc yBscd;
    array mBsc   (p) mBsca  mBscb  mBscc mBscd;

  /*year end cohabitating */

    array yeca  (t) M48001Y M920011Y M920012Y M920013Y ;
    array yecb  (t) M48002Y M920021Y M920022Y yecb4;
    array yecc  (t) M48003Y M920031Y yecc3 yecc4;
    array yecd  (t) M48004Y  yecd2 yecd3 yecd4;
           array yec   (p) yeca yecb yecc yecd;

  /*month end cohabitating */

    array meca  (t) M48001M M920011M M920012M M920013M;
    array mecb  (t) M48002M M920021M M920022M  mecb4;
    array mecc  (t) M48003M M920031m mecc3  mecc4;
    array mecd  (t) M48004m mecd2    mecd3  mecd4;
           array mec   (p) meca mecb mecc mecd;

    /*continuous start month of cohabitation*/
    array csmca (t) csmca1 csmca2 csmca3 csmca4;
    array csmcb (t) csmcb1 csmcb2 csmcb3 csmcb4;
    array csmcc (t) csmcc1 csmcc2 csmcc3 csmcc4;
    array csmcd (t) csmcd1 csmcd2 csmcd3 csmcd4;
          array csmc  (p) csmca csmcb csmcc csmcd;

    /*continuous end month of cohabitation*/
    array cemca (t) cemca1 cemca2 cemca3 cemca4;
    array cemcb (t) cemcb1 cemcb2 cemcb3 cemcb4;
    array cemcc (t) cemcc1 cemcc2 cemcc3 cemcc4;
    array cemcd (t) cemcd1 cemcd2 cemcd3 cemcd4;
       array cemc  (p) cemca cemcb cemcc cemcd;

  /* continuous start month of marriage*/

    array csmma (t) csmma1 csmma2 csmma3 csmma4;
    array csmmb (t) csmmb1 csmmb2 csmmb3 csmmb4;
    array csmmc (t) csmmc1 csmmc2 csmmc3 csmmc4;
    array csmmd (t) csmmd1 csmmd2 csmmd3 csmmd4;
          array csmm  (p) csmma csmmb csmmc csmmd;

  /* continuous start month of separation */

    array csmsa (t) csmsa1 csmsa2 csmsa3 csmsa4;
    array csmsb (t) csmsb1 csmsb2 csmsb3 csmsb4;
    array csmsc (t) csmsc1 csmsc2 csmsc3 csmsc4;
    array csmsd (t) csmsd1 csmsd2 csmsd3 csmsd4;
          array csms  (p) csmsa csmsb csmsc csmsd;

  /* continuous end month of marriage*/

    array cemma (t) cemma1 cemma2 cemma3 cemma4;
    array cemmb (t) cemmb1 cemmb2 cemmb3 cemmb4;
    array cemmc (t) cemmc1 cemmc2 cemmc3 cemmc4;
    array cemmd (t) cemmd1 cemmd2 cemmd3 cemmd4;
          array cemm  (p) cemma cemmb cemmc cemmd;

  /*continuous end month of separation  */

    array cemsa (t) cemsa1 cemsa2 cemsa3 cemsa4;
    array cemsb (t) cemsb1 cemsb2 cemsb3 cemsb4;
    array cemsc (t) cemsc1 cemsc2 cemsc3 cemsc4;
    array cemsd (t) cemsd1 cemsd2 cemsd3 cemsd4;
       array cems  (p) cemsa cemsb cemsc cemsd;

  /* dummy for cohabitation continuous - since dli*/
    array cdlia (t) M46701 cdlia2 cdlia3 cdlia4;
    array cdlib (t) M46702 cdlib2 cdlib3 cdlib4;
    array cdlic (t) M46703 cdlic2 cdlic3 cdlic4;
    array cdlid (t) M46704 cdlid2 cdlid3 cdlid4;
    array cdli  (p) cdlia cdlib cdlic cdlid;

  /* dummy for cohabitation continuous - since start (after dli date for new partners) */

    array cbega (t) M47001 cbega2 cbega3 cbega4;
    array cbegb (t) M47002 cbegb2 cbegb3 cbegb4;
    array cbegc (t) M47003 cbegc2 cbegc3 cbegc4;
    array cbegd (t) M47004 cbegd2 cbegd3 cbegd4;
    array cbeg  (p) cbega cbegb cbegc cbegd;

    /*  cohabitation continuous - since start (after dli date) */

    array cbeg2a (t) cbeg2a1 M910011 M910012 M910013;
    array cbeg2b (t) cbeg2b1 M910021 M910022 cbeg2b4;
    array cbeg2c (t) cbeg2c1 M910031 cbeg2c3 cbeg2c4;
    array cbeg2d (t) cbeg2d1 cbeg2d2 cbeg2d3 cbeg2d4;
     array cbeg2 (p) cbeg2a cbeg2b cbeg2c cbeg2d;

    /* legally married when begian cohabitating*/

    array mbega (t) M45001 mbega2 mbega3 mbega4;
    array mbegb (t) M45002 mbegb2 mbegb3 mbegb4;
    array mbegc (t) M45003 mbegc2 mbegc3 mbegc4;
    array mbegd (t) M45004 mbegd2 mbegd3 mbegd4;
         array mbeg  (p) mbega mbegb mbegc mbegd;

   /*marital/cohabitation status at date of last interview*/

    array mdlia (t) mardli   mdlia2 mdlia3 mdlia4;
    array mdlib (t) mdlib1   mdlib2 mdlib3 mdlib4;
    array mdlic (t) mdlic1   mdlic2 mdlic3 mdlic4;
    array mdlid (t) mdlid1   mdlid2 mdlid3 mdlid4;
    array mdli  (p) mdlia mdlib mdlic mdlid;

   /* First | next change in status.   Read "cstata2" as change in marital status for partner a, period 2. */

   array cstata1 (t) m540011   m540012   m540013   m540014;
   array cstata2 (t) m7900111  m7900112  cstata23  cstata24;
   array cstatb1 (t) m7900211  m7900212  m540021   cstatb13;
   array cstatc1 (t) m7900311  cstatc12  cstatc13  cstatc14;

   array cstata3 (t) m9800111  cstata32  cstata33  cstata34;    /* added 11-15-07*/
   array cstatb2 (t) m9800211  m9800212  cstatb23  cstatb24;

  /*collapse into cstat status changed*/

    array cstat1  (p) cstata1 cstatb1 cstatc1 cstatd1;
    array cstat2  (p) cstata2 cstatb2 cstatc2 cstatd2;
    array cstat3  (p) cstata3 cstatb3 cstatc3 cstatd3;
    array cstat4  (p) cstata4 cstatb4 cstatc4 cstatd4;

         array cstat  (i) cstat1 cstat2 cstat3 cstat4 ;
           /*month & year change is marry*/

    array cyma1 (t)  M570011y   M570012y      M570013y   m570014y;
    array cmma1 (t)  M570011m   M570012m      M570013m   m570014m;
    array cyma2 (t)  m8200111y  cyma22        cyma23     cyma24;
    array cmma2 (t)  m8200111m  cmma22        cmma23     cmma24;
    array cymb1 (t)  m8200211y  m8200212y     m570021m   cymb14;
    array cmmb1 (t)  m8200211m  m8200212m     m570021y   cmmb14;
    array cymc1 (t)  m8200311y  cymc12        cymc13     cymc14;
    array cmmc1 (t)  m8200311m  cmmc12        cmmc13     cmmc14;
    array cyma3 (t)  m10100111y  cyma32       cyma33     cyma34;      /* add 11-15-07 */
    array cmma3 (t)  m10100111m  cmma32       cmma33     cmma34;
    array cymb2 (t)  m10100211y  m10100212y   cymb23     cymb24;     /* add 11-15-07 */
    array cmmb2 (t)  m10100211m  m10100212m   cmmb23     cmmb24;

  /*collaspse into month & year change is marry*/

    array cym1  (p) cyma1 cymb1 cymc1 cymd1;
    array cmm1  (p) cmma1 cmmb1 cmmc1 cmmd1;
    array cym2  (p) cyma2 cymb2 cymc2 cymd2;
    array cmm2  (p) cmma2 cmmb2 cmmc2 cmmd2;
    array cym3  (p) cyma3 cymb3 cymc3 cymd3;
    array cmm3  (p) cmma3 cmmb3 cmmc3 cmmd3;
    array cym4  (p) cyma4 cymb4 cymc4 cymd4;
    array cmm4  (p) cmma4 cmmb4 cmmc4 cmmd4;
    array cym (i) cym1   cym2  cym3  cym4;
    array cmm (i) cmm1   cmm2  cmm3  cmm4;

  /*month and year change=separation, divo_, annulment*/

    array cyssa1 (t) M560011Y  M560012Y M560013Y M560014Y;
    array cmssa1 (t) M560011M  M560012M M560013M M560014M;
    array cyssa2 (t) M8100111Y M8100112Y cyssa23 cyssa24;
    array cmssa2 (t) M8100111M M8100112M  cmssa23 cmssa24;
    array cyssa3 (t) M8100211Y m8100212Y m560021y cyssa34;
    array cmssa3 (t) M8100211M m8100212M m560021m cmssa34;
    array cyssa4 (t) cyssa41   cyssa42 cyssa43 cyssa44;
    array cmssa4 (t) cmssa41   cmssa42 cmssa43 cmssa44;

   /*collapse into month and year change=separation, divo_, annulment*/

    array cyss1  (p) cyssa1 cyssb1 cyssc1 cyssd1;
    array cmss1  (p) cmssa1 cmssb1 cmssc1 cmssd1;
    array cyss2  (p) cyssa2 cyssb2 cyssc2 cyssd2;
    array cmss2  (p) cmssa2 cmssb2 cmssc2 cmssd2;
    array cyss3  (p) cyssa3 cyssb3 cyssc3 cyssd3;
    array cmss3  (p) hmsas3 cmssb3 cmssc3 cmssd3;
    array cyss4  (p) cyssa4 cyssb4 cyssc4 cyssd4;
    array cmss4  (p) cmssa4 cmssb4 cmssc4 cmssd4;
    array cyss  (i) cyss1   cyss2  cyss3   cyss4;
    array cmss  (i) cmss1   cmss2  cmss3   cmss4;

  /* Current staus of relationship */

    array fstata (t) M114001 fstata2 fstata3   fstata4;
    array fstatb (t) M114002 fstatb2 fstatb3   fstatb4;
    array fstatc (t) M114003  fstatc2 fstatc3  fstatc4;   /*  fstatc1 fstatc2 fstatc3 fstatc4; */
    array fstatd (t) M9800111  fstatd2 fstatd3 fstatd4;
          /*collapse married into array*/

      array fstat (p) fstata fstatb fstatc fstatd;

  /* month & year relationship ended */

    array eyra  (t) M117001Y    eyra2 eyra3 eyra4;
    array eyrb  (t) M117002Y    eyrb2 eyrb3 eyrb4;
    array eyrc  (t) M117003Y    eyrc2 eyrc3 eyrc4;               /*eyrc1 eyrc2     eyrc3 eyrc4;*/
    array eyrd  (t) M10000111Y  eyrd2 eyrd3 eyrd4;

    array emoa  (t) M117001M   emoa2 emoa3 emoa4;
    array emob  (t) M117002M   emob2 emob3 emob4;
    array emoc  (t) M117003M   emoc2 emoc3 emoc4;                   /* emoc2 emoc2     emoc3 emoc4; */
    array emod  (t) M10000111M  emod2 emod3 emod4;

   /*collapse all start years & months into arrays*/

     array eyr   (p) eyra eyrb eyrc eyrd;
     array emo   (p) emoa emob emoc emod;

  /*R/PART GET LEGAL divo_/ANNULMENT   */   /* round 9 added*/

    array divoa (t) M4350A1 divoa2 divoa3 divoa4;
    array divob (t) M4350A2 divob2 divob3 divob4;
    array divoc (t) M4350A3 divoc2 divoc3 divoc4;
    array divod (t) divod1  divod2 divod3 divod4;

          /*collapse divo_d into array*/

      array divo (p) divoa divob divoc divod;
  /* month & year divo_d */

    array divoya  (t) M4360A1y divoya2 divoya3 divoya4;
    array divoyb  (t) M4360A2y divoyb2 divoyb3 divoyb4;
    array divoyc  (t) divoyc1  divoyc2 divoyc3 divoyc4;
    array divoyd  (t) divoyd1  divoyd2 divoyd3 divoyd4;

    array divoma  (t) M4360A1M divoma2 divoma3 divoma4;
    array divomb  (t) M4360A2M divomb2 divomb3 divomb4;
    array divomc  (t) divomc1  divomc2 divomc3 divomc4;
    array divomd  (t) divomd1  divomd2 divomd3 divomd4;

     /*collapse all divo_d years & months into arrays*/

    array divoy   (p) divoya divoyb divoyc divoyd;
    array divom   (p) divoma divomb divomc divomd;

   /*R/PART GET ANNULMENT   */   /* round 10 added*/

    array annua (t) M4350A1 annua2 annua3 annua4;
    array annub (t) M4350A2 annub2 annub3 annub4;
    array annuc (t) annuc1 annuc2 annuc3 annuc4;
    array annud (t) annud1  annud2 annud3 annud4;

          /*collapse annurced into array*/

      array annu (p) annua annub annuc annud;
  /* month & year annulment */

    array annuya  (t) m4370A1y annuya2 annuya3 annuya4;
    array annuyb  (t )m4370A2y annuyb2 annuyb3 annuyb4;
    array annuyc  (t) annuyc1  annuyc2 annuyc3 annuyc4;
    array annuyd  (t) annuyd1  annuyd2 annuyd3 annuyd4;

    array annuma  (t) m4370A1M annuma2 annuma3 annuma4;
    array annumb  (t) m4370A2m annumb2 annumb3 annumb4;
    array annumc  (t) annumc1  annumc2 annumc3 annumc4;
    array annumd  (t) annumd1  annumd2 annumd3 annumd4;

     /*collapse all annurced years & months into arrays*/

    array annuy   (p) annuya annuyb annuyc annuyd;
    array annum   (p) annuma annumb annumc annumd;

  /*5-14-02 Collapsed marital status*/
    array cmarsa (t) cmarsa1 cmarsa2 cmarsa3 cmarsa4;
    array cmarsb (t) cmarsb1 cmarsb2 cmarsb3 cmarsb4;
    array cmarsc (t) cmarsc1 cmarsc2 cmarsc3 cmarsc4;
    array cmarsd (t) cmarsd1 cmarsd2 cmarsd3 cmarsd4;

       array cmars (p) cmarsa cmarsb cmarsc cmarsd;

   /* imars individual  marital status */

    array imarsa (t) imarsa1 imarsa2 imarsa3 imarsa4;
    array imarsb (t) imarsb1 imarsb2 imarsb3 imarsb4;
    array imarsc (t) imarsc1 imarsc2 imarsc3 imarsc4;
    array imarsd (t) imarsd1 imarsd2 imarsd3 imarsd4;
          array imars (p) imarsa imarsb imarsc imarsd;

    array coha   (t) cohaf cohas  cohat cohafour;
    array cohb   (t) cohbf cohbs  cohbt cohbfour;
    array cohc   (t) cohcf cohcs  cohct cohcfour;
    array cohd   (t) cohdf cohds  cohdt cohdfour;
        array coh (p) coha cohb cohc cohd ;

    array ma     (t) maf mas mat mafour;
    array mb     (t) mbf mbs mbt mbfour;
    array mc     (t) mcf mcs mct mcfour;
    array md     (t) mcf mcs mdt mdfour;
     array m     (p) ma mb mc md;

  do l=1 to dlicm;
       if l=dlicm then do;
          cohhR13=R13co;
          marsR13=R13mars;
          linkR13=R13link;
      end;
  end;

%let n=4;
array  slink(&n); array  sco(&n);

do i=1 to (&n);
      slink{i}= -4;
      sco{i}=-4;
end;
drop i;

do i=1 to (&n);   /* loop one */
   do l=169 to dlicm until (R13mars=2 & R13co=200+i);
        if R13mars=2  & R13co=200+i
         then
         do ;
            slink{i}=R13link;
            sco{i}=R13co;
             end;
   end;
end;   /* end loop one */

  /* married & spouse are not living HH | spouse are missing in previous rounds and
 come back in current round */

   flaglink=0;
 do i=1 to 3;   /* loop one */
    if slink{i}>0 then flaglink=1;
      do l=169 to dlicm until (R13mars=2 & R13co=-4);
          if R13mars=2 & R13co=-4 & flaglink=0 then do ;
             slink{i}=R13link;
             sco{i}=R13co;
              if cohhR13=-4  & flagp=1 & dlimarstat<5 then do;
                 cohhR13=201;
                 if premar_ttl=2 then cohhR13=202;
                 end;
              end;
        end;
 end;   /* end loop one */

 do i=1 to 3;
     if slink{i} =slink{i+1}  then slink{i+1}=-4;
     if slink1=slink3 & slink3>0 then slink3=-4;
 end;

 flags=0;
 do t=1 to 4;
       do i=1 to 4;
         if slink{i} =par{t} & slink{i}>0 & flagp=1 then  flags=1;
       end;
 end;

/* partner is back in current round */
do t=1 to 4;
        do i=1 to 4;
         if (cohhR13<=-4 or cohhR13=.) & flagp=1 & precoh_ttl >0  then do ;
         if -3<dlimarstat<3 then cohhR13=100+precoh_ttl;
         if dlimarstat>3 & flags=0 then cohhR13=100+precoh_ttl;
        end;
    end;
end;

do t=1 to 4;
       do i=1 to 4;
       if  cohhR13<=-4 or cohhR13=.& flags=1 & flagp=1 then do;   /* 12-19-2011  pubid=  2911*/
       if (3<=dlimarstat<=4 | dlimarstat=-3 ) then  cohhR13=200+premar_ttl;
          if 5<=dlimarstat<=6  then cohhR13=200+premar_ttl;
          if 7<=dlimarstat<=8  then  cohhR13=200+premar_ttl;
      end;
   end;
end;

if pubid= 5076 then m45001=1;

do p=1 to 4;          /* R14 */
   do t=1 to 4;
       do i=1 to 4;
           if 100<cohhR13<200 & flags=1  then do;
           if dlimarstat in (4)  & slink(i)=par(i) & ysc>-4  & cemm in (-4, .) & m620 ~=3 then do;
              mbeg=1;
              cohhR13=200+premar_ttl;
         end;
      end;
    end;
  end;
end;

if pubid= 5076 then m45001=1;    /* 1-19-2019  pubid= 5076*/
if pubid= 6879 then cohhr13=102;

do p=1 to 4; /* loop for p */
      do t=1 to 4; /* loop for t */
            if cdli=1 then do;
            csmc=dlicm;
            end;
            if -4<cdli<0 then cdli=0;
            if cdli=0  then csmc=dlicm;
            if( mdli=1 | mdli=2)  then cmars=0;
            if (mdli=3 | mdli=4)  then do;
            cmars=1;
            csmm=dlicm;
              cemm=doicm;
        end;

           if mdli=5 | mdli=6  then do;
            cmars=2;
            csms=dlicm;
              cems=doicm;
           end;

           if mdli=7 | mdli=8  then do;
              cmars=3;
              csms=dlicm;
              cems=doicm;
           end;

           if mdli=9 | mdli=10 then do;
            cmars=4;   /* R12 added  widowed in last round*/
            imars=4;
            csms=dlicm;
            cems=doicm;
            end;

         if mdli<0 & mdli ^= -4 then cmars=mdli;

         if mdli=-3 & premar_ttl>0 then   do; /* added R12   4 obs in Round 9*/
            cmars=1;
            csmm=dlicm;
            end;

 if ysc>0 & msc>0 & ysc gt bdate_y then csmc=(ysc-1980)*12+msc;

   /*  If a start year | month  is missing & flagp ^= 1 then I'm setting it to dli. */
       if (-3 le ysc le 0  | -3 le msc le 0)  then csmc=dlicm;

   /*  If a start year is know & month are missing,then I'm setting it to Janurary */
       if ysc > 0 &  -3 <= msc <= 0 then csmc=(ysc-1980)*12+1;
        if yec>0 & mec>0 & yec gt bdate_y then cemc=(yec-1980)*12+mec-1;
           if csmc=cemc+1 & cemc>0 then cemc=cemc+1;                 /*add at R14*/
          if (-3 <=yec <= 0 | -3 <= mec <= 0)  & (cbeg ^= 1 &/* cbeg2 ^=1  &*/ cdli^= 1)  then  cemc=doicm-1;
           if (-3 <=yec <= 0 | -3 <= mec <= 0) & (fstat=3 | fstat=4) & eyr >0 & emo >0 then  cemc=(yec-1980)*12+mec-1;
            if yec>0 & -4<mec<0 then do;
            cemc=(yec-1980)*12+12-1;  /* set as December */
             if cemc>=doicm then cemc=doicm-1;     /* added 2-2-11 R14 */
             end;
              if (cdli=1 | cbeg=1) | (cbeg2=1) then cemc=doicm;   /* Changed 10-17-11) */
                if cdli=1 & m620=4 & slink(t)=par(p) then cemc=doicm-1;   /* Changed 10-31-11) R14 */
                if dlimarstat=4 & csmc>-4 &  slink(t)=p1 & p2=-4 then do ;
                if  mbeg=0 then mbeg=1;           /* added 11-2-11) R14 */
                end;
 if mbeg=1  then do;
        cmars=1;
        imars=1;
        csmm=csmc;
          cemm=cemc;
        ymsc=.;
    if  (dlimarstat=3 | dlimarstat=4) & (cbeg=1 | yec>-4) & slink(t)=par(p)  then do; /*  added in R12 Spouse come back in HH and live together */
        cmars=1;
        imars=1;
        csmm=start;
        ymsc=.;
       end;
    if (dlimarstat=7 | dlimarstat=8) & premar_ttl=1 then do;  /* added in R13 married  marriage with p=1301*/
        cmars=3;
        imars=3;
        csms=start;
          cems=csmma1;
        ymsc=.;
       end;
end;
    if -4<mbeg<0 then mbeg=-4; /* two cases in Round 9.  R12 added*/
     if mbeg=0 then imars=0;
      if mbeg=-4 & cmars ^= . & cohhR13 gt 200 then imars=1;
       else if mbeg=-4 & cmars ^= . & cmars ^= -4 & 100 < cohhR13< 200 then imars=0;

       /* This loop 1 will help to reserve the information from last round, without
 this loop,  the old information. could be overwriten by the loops following. */

      C =0;
        do l=1 to doicm; /* loop 1 */
          C=C+1;
          if csmc>0 & cemc>0 & csmc LE C LE cemc then cohal=1;
          if csmc>0 & cemc>0 & csmc LE C LE cemc then coh=1;
          if cmars=1 & csmm>0 & cemm>0 & csmm le c le cemm then mal=1;
          if imars=1 & csmm>0 & cemm>0 & csmm le c le cemm then m=1;
          if 2 le cmars le 3 & csms>0 & cems>0 & csms le c le cems then mal=cmars;
          if 2 le imars le 3 & csms>0 & cems>0 & csms le c le cems then m=imars;
          if  cmars =4 & csms>0 & cems>0 & csms le c le cems then mal=cmars;  /*     added in round 9*/
          if  imars =4 & csms>0 & cems>0 & csms le c le cems then m=imars;    /*     added in round 9*/
          if cmars=0 then  mal=cmars;
          if -2 le cmars le -1 then mal=cmars;
          if -2 le imars le -1 then m=imars;
        end;   /* end loop 1 */

  array edit4360a(4)  edit4360a1-edit4360a4;
  do i=1 to 4;
   if divoy>0 & divom>0 then do;
      edit4360a(i)=(divoy -1980)*12 +divom;
   end;
  end;
        if divo=1  then do;
            if  divoy>0 & divom>0 then do;
              cmars=3;
              imars=3;
              csms=(divoy-1980)*12 +divom;
              cems=doicm;
          end;

      if  (-4<divoy<0 | -4<divom<0) then  do;
              cmars=3;
              imars=3;
              csms=start;
              cems=doicm;
        end;

      if (divoy>0 & -4<divom<0) then
        do;
            cmars=3;
            imars=3;
            csms=( divoy-1980)*12 +12;  /* set divo_ month as dec    */
            cems=doicm;
            if csms>cems then  csms=cems;  /* added R14 */
        end;
  end;

     if  (divo=2 )  & annuy>0 & annum>0 then do;
              cemc=(annuy-1980)*12 +annum;
              cmars=0;
              imars=0;
                cemm=cemc;
                csmm=start;
           end;

         do i=1 to 4; /* Loop 2 */

            if cstat=1 & cym>0 & cmm>0 then do;
                    cmars=1;
                    imars=1;
                      csmm=(cym-1980)*12+cmm;
               end;
            if -2 le cstat le -1  & (cym>-4 & cmm>-4 )then do;
                   cmars=cstat;
                   imars=cstat;
               end;

            if cstat=1 & (-4<cym<0 | -4<cmm<0) then do;
                   cmars=1;
                   imars=1;
                   csmm=dlicm;
                end;

            /* Marriage ends in legal separation */

            if cstat=3 & cyss>0 & cmss>0 then do;
                  cmars=2;
                  imars=2;
                  csms=(cyss-1980)*12+cmss;
             end;

            if cstat=3 & (-4<cyss<0 | -4<cmss<0) then do;
                  cmars=2;
                  imars=2;
                  csmm=doicm;
              end;

           /* Marriage ends in divoice */

           if cstat=4 & cyss>0 & cmss>0 then do;
                  cmars=3;
                  imars=3;
                  csms=(cyss-1980)*12+cmss;
              end;

           /*   Get an annulment    */

            if cstat=5 & cyss>0 & cmss>0 then
              do;
                  cmars=3;
                  imars=3;
                  csms=(cyss-1980)*12+cmss;
              end;
            if csms>0 then cems=doicm;
            if csmm>0 then cemm=doicm;

          /* YMAR-114000 (fstat in the arrays) collects current status of the relationship.*/

      if fstat=2 & 0<dlimarstat<3 then do;
         cmars=0; /* fstat=annulment, which translates into never married in collapsed mar. status */
         imars=0; /* 3 cases in round 9*/
         end;
      if fstat=3 & eyr>0 & emo>0 then
        do;
         cmars=2;                    /* separation */
         imars=2;
         csms=(eyr-1980)*12 + emo;
         cems=doicm;    /*10-27-05*/
        end;

     if cstat=1 & cym>0 & cmm>0 then
         do;
               cmars=1;
               imars=1;
              /* ymsm=cym*100+cmm;*/ csmm=(cym-1980)*12+cmm;
               cmarsa1=1;    /* added in R7  Three R's married  Round 7, then legal separated several month late */
               imarsa1=1;
             end;

      if fstat=3 & (-4<eyr<0 & -4<emo<0) then do;
         cmars=2;
         imars=2;
         csms=doicm;
         cems=doicm;    /*10-27-05*/
         end;

       if fstat=3 & (eyr>0 & -4<emo<0) then do;
         cmars=2;
         imars=2;
         csms=(eyr-1980)*12 + 12;  /* 12: dec 2008 */
       if csms>doicm then csms=doicm;   /* added jan-2010*/
         cems=doicm;    /*10-27-05*/
      end;

      if fstat=4 & eyr>0 & emo>0  then do;
         cmars=3;
         imars=3;
         csms=(eyr-1980)*12 + emo;
         cems=doicm;    /*10-27-05*/
        end;

      if fstat=4 & (-4<eyr<0 | -4<emo<0) then
          do;
         cmars=3;
         imars=3;
         csms=doicm;
         cems=doicm;    /*10-27-05*/
           end;
            if fstat=4 & (eyr>0 & -4<emo<0) then
       do;
         cmars=3;
         imars=3;
         csms=(eyr-1980)*12 + 12  ;  /* added 2-6-09  */
         if csms>doicm then csms=doicm ;
         cems=doicm;    /*10-27-05*/
         end;

      if fstat=5 & eyr>0 & emo>0 & csmm>0 then do;
              cmars=4;
             imars=4;  /*10-31-03 widowed */
         csms=(eyr-1980)*12 + emo;
         widow=1;
       end;

      if fstat=5 & (-4<eyr<0 | -4<emo<0) & csmm>0  then
       do;
           cmars=4;
           imars=4;
           csms=doicm;
           widow=1;
       end;
          if csms>0 then cems=doicm;
          if -4<fstat<0  & -4<m620<0 then cmars=fstat;

      end;

  /*Category "Death" is missing from Round 9 to Round 12.

  Current interview dates were used as spouse death dates in Round 12. */

  if m620=4  & pubid ~=2337   then do;
           cmars=4;
           imars=4;
           csms=doicm;
           cems=doicm;
           widow=1;
   end;
      /* spouse living ourside the household*/ /*R12 added*/

     do l=start to doicm;/*loop 1  */
        if ysp>0 & msp>0 then
               do;
              csmm = (ysp-1980)*12+msp;
              cemm=doicm;
              cmars=1;
              imars=1;
              marcm=csmm ;

           if edit4360a1>0 then do;
              cemm=edit4360a1-1;  /* add in Round 11 for pubid=1982 */
              cmars=3;
              imars=3;
            end;

           if  fstat=3 & eyr>0 & emo>0 then do;     /* add in Round 12 for     pubid=7758 */

             cmars=2;                 /* separation */
             imars=2;
            csms=(eyr-1980)*12 + emo;
            cems=doicm;    /*10-27-05*/
            end;
         end;

             if  -4<ysp<0 & -4<msp<0 then
               do;
               csmm=start;
               cemm=doicm;
               cmars=1;
               imars=1;
               marcm=-3;
               marm=-3;
               mary=-3;
             end;
     end;/*end of loop l */

     if mbeg=1 & (dlimarstat=7 | dlimarstat=8) & premar_ttl=1 then  cems=csmm-1;

  /* Now that the start & end dates of marriages/cohabs are created, we can place
 that information into the array. The information from the last week is used to create the variable for
 marital status & collapsed marital  status. */

     C=0;
       do l=1 to doicm; /* loop 1 */
        C=C+1;
         if csmc>0 & cemc>0 & csmc LE C LE cemc then cohal=1;
         if csmc>0 & cemc>0 & csmc LE C LE cemc then coh=1;
         if cmars>=1 & csmm>0 & cemm>0 & csmm le c le cemm then mal=1;
         if imars>=1 & csmm>0 & cemm>0 & csmm le c le cemm then m=1;
         if  cmars = 2 & csms>0 & cems>0 & csms le c le cems then mal=2;
         if  imars = 2 & csms>0 & cems>0 & csms le c le cems then m=2;
         if  cmars = 3 & csms>0 & cems>0 & csms le c le cems then mal=3;
         if  imars = 3 & csms>0 & cems>0 & csms le c le cems then m=3;
         if  cmars = 4 & csms>0 & cems>0 & csms le c le cems then mal=4;
         if  imars = 4 & csms>0 & cems>0 & csms le c le cems then m=4;
         if -2 le cmars le -1 then mal=cmars;
         if -2 le imars le -1 then m=imars;
         if cmars=0 then  mal=cmars;

       if c=doicm then do;
         if mal in (-1,-2)  then mars=-3;
         if mal=0 & cohal=1 then mars=1;
         if mal=0 & cohal=0 then mars=2;
         if mal=1 & cohal=1 then mars=3;
         if mal=1 & cohal=0 then mars=4;
         if mal=2 & cohal=1 then mars=5;
         if mal=2 & cohal=0 then mars=6;
         if mal=3 & cohal=1 then mars=7;
         if mal=3 & cohal=0 then mars=8;
         if mal=4 & cohal=1 then mars=9;
         if mal=4 & cohal=0 then mars=10;
             marstat=mars;
          end; /* end of loop  C  */
     end; /* end of loop l  */
   end;/* end of loop t*/
  end;/*end of loop p*/

  /*  Create collapsed marital status from marital status.*/
   if  1   le marstat le 2    then   cmarstat=0;
   if  3   le marstat le 4    then   cmarstat=1;
   if  5   le marstat le 6    then   cmarstat=2;
   if  7   le marstat le 8    then   cmarstat=3;
   if  9   le marstat le 10   then   cmarstat=4;
   if -2   le marstat le -1   then   cmarstat=marstat;
  if marstat=-3 then cmarstat=-3;

  /* Finding continue month of first cohabitation & first marriage */

  do p=1 to 4; /* loop for p */
        do t=1 to 4; /* loop for t */
                 do i=1 to 4;   /* loop for  i  */
                       if yco>0 & mco>0  then do;
                           ymco=((yco-1980)*12)+mco;
                          cohcm=  min (ymcoa1, ymcoa2, ymcoa3, ymcoa4,
                                   ymcob1, ymcob2, ymcob3, ymcob4,
                                   ymcoc1, ymcoc2, ymcoc3, ymcoc4,
                                   ymcod1, ymcod2, ymcod3, ymcod4);
                               end;

                                if cym >0 & cmm>0  & csmm>0 then do;
                          marcm= min(csmma1, csmma2, csmma3, csmma4,
                                     csmmb1, csmmb2, csmmb3, csmmb4,
                                     csmmc1, csmmc2, csmmc3, csmmc4,
                                     csmmd1, csmmd2, csmmd3, csmmd4);
                                   end;
                                 if mbeg=1 then do;
                                       if dlicohcm<=-4 & dlimarcm<=-4 then do;
                                          marcm=cohcm;
                                          cohcm=-4;
                                       end;
                              else if dlicohcm>=-3 and dlimarcm<=-4 then do;
                           marcm=cohcm;
                        end;
                     end;
               end;
       end;
  end;

  array cvcm  cohcm marcm;
  array cvy   cohy  mary;
  array cvm   cohm  marm;
  array fir   firstc384-firstc157;

  do over cvcm;

              do i=384 to 157 by -12;              /*  384 Dec 2010  */
                     fir=i;
                    if  fir-11<=cvcm<=fir then do;
                        cvm=cvcm-(fir-12);          /* 10/05= 310  10=310-(312-12)   */
                        cvy=(cvcm-cvm)/12+1980;
                    end;
              end;
                  if cvcm=. then do;
                    cvcm=-4;
                    cvy=-4;
                    cvm=-4;
                 end;
  end;

  if cohcm<0 then do;   /* loop one */     /*  10-18-07 */
  do p=1 to 4;
          do t=1 to 4;
                       do i=1 to 4;
                      if  -4<ysc<0 & -4<msc<0  then do;
                        cohm=-3;
                        cohy=-3;
                        cohcm=-3;
                       end;

                      if -4<ysc<0 & msc>0 then do;
                       cohm=msc;
                       cohy=-3;
                       cohcm=-3;
                    end;

                    if ysc>0 & -4<msc<0  then do;
                        cohm=-3;
                        cohy=ysc;
                        cohcm=-3;
                    end;
                 end;
           end;
      end;

  end;/*loop one */

  do p=1 to 4;
          do t=1 to 4;
                       do i=1 to 4;
                    if -4<cym<0 & -4<cmm<0 & marcm<0  then  do;
                      marm=-3;
                      mary=-3;
                      marcm=-3;
                   end;

                   if -4<cym<0 & cmm>0 & marcm<0 then  do;
                     marm=cmm;
                     mary=-3;
                     marcm=-3;
                    end;

                   if cym>0 & -4<cmm<0 & marcm<0 then do;
                     marm=-3;
                    mary= /* min (cyma2, cymb1 );   */ cym;
                     marcm=-3;
                  end;
         end;
     end;
  end;

  do p=1 to 4;

     do t=1 to 4;
         if mbeg=1  then do;
         if -3<ysc<0 & -3<msc<0 &  dlicohcm=-4 & dlimarm=-4 then  do;   /* one case    in R12*/
                cohm=-4;
                cohcm=-4;
                cohy=-4;
                marcm=-3;
                mary=-3;
                marm=-3;
        end;

         if  ysc>0 & -3<msc<0 &  dlicohcm=-4 & dlimarm=-4 then
         do;   /* one case in R12*/

                cohm=-4;
                cohcm=-4;
                cohy=-4;
                marcm=-3;
                mary= min(ysca, yscb,yscc);   /* r14  changed */
                marm=-3;
         end;

                if -3<ysc<0 & msc>0 &  dlicohcm=-4 & dlimarm=-4 then
         do;
                cohm=-4;
                cohcm=-4;
                cohy=-4;
                marcm=-3;
                mary=-3;
                marm=msc;
         end;
     end;
   end;
 end;

do p=1 to 4;
    do t=1 to 4;
       if mbeg=1 then do;
        if  -3<ysc<0 & -3<msc<0 &   dlimarm=-4  & dlicohcm>-4 then
        do;   /* one case in R12*/
                marcm=-3;
                mary=-3;
                marm=-3;
        end;
        if ysc>0 & -3<msc<0  & dlimarm=-4 & dlicohcm>-4 then

         do;   /* no case in R12*/

                marcm=-3;
                mary=ysc;
                marm=-3;
         end;
                if -3<ysc<0 & msc>0  & dlimarm=-4 & dlicohcm>-4 then

         do;   /* no case in R12   */

                marcm=-3;
                mary=-3;
                marm=msc;
         end;
     end;
   end;
 end;

 do p=1 to 4;     /* 12-8-2011 */
    do t=1 to 4;
       if M45001=0 & M45002=1 &  dlicohcm = -4 then do;
       if m31001m>0 & m31001y>0 then do;
               cohm= m31001m;
               cohy=  m31001y;
               cohcm= m31001cm;
            end;
        end;
    end;
end;

  /*if old date present & don't deny then use old date*/

if  dlicohm >-4  then do;
      cohcm= dlicohcm;
      cohy=  dlicohy;
      cohm= dlicohm;
end;

if dlimarcm>-4 then do;
      marcm=dlimarcm;
      mary=dlimary;
      marm=dlimarm;
end;

       /*Marital status for event history*/

    do l=start to doicm;
            if -2 le mal le -1  then  mars=-3;
            if mal=0 & cohal=1 then mars=1;
            if mal=0 & cohal=0 then mars=0;
            if mal=1 & cohal=1 then mars=2;
            if mal=1 & cohal=0 then mars=2;
            if mal=2 & cohal=1 then mars=3;
            if mal=2 & cohal=0 then mars=3;
            if mal=3 & cohal=1 then mars=4;
            if mal=3 & cohal=0 then mars=4;
            if mal=4 & cohal=1 then mars=5;
            if mal=4 & cohal=0 then mars=5;
    end;

  /* for the documentation except the marital status;*/

      do l=start to doicm;
         if cohaf=1 | cohas=1 | cohat=1 | cohafour=1 then cohaa=1;
         if cohbf=1 | cohbs=1 | cohbt=1 | cohbfour=1 then cohbb=1;
         if cohcf=1 | cohcs=1 | cohct=1 | cohcfour=1 then cohcc=1;
         if cohdf=1 | cohds=1 | cohdt=1 | cohdfour=1 then cohdd=1;
         if maf=1 | mas=1 | mat=1 | mafour=1 then maa=1;
         if mbf=1 | mbs=1 | mbt=1 | mbfour=1 then mbb=1;
         if mcf=1 | mcs=1 | mct=1 | mcfour=1 then mcc=1;
         if mdf=1 | mds=1 | mdt=1 | mdfour=1 then mdd=1;
      end;
           /* Mar-Cohabitation;*/
  do l=start to doicm;
    if cohdd=1 then cohh=104;
    if cohcc=1 then cohh=103;
    if cohbb=1 then cohh=102;
    if cohaa=1 then cohh=101;

    if mdd=1 & cohdd=1 then cohh=204;  /* added in Round 9*/
    if mcc=1 & cohcc=1 then cohh=203;
    if mbb=1 & cohbb=1 then cohh=202;
    if maa=1 & cohaa=1 then cohh=201;
   end;

          /* Mar_Dual */

  do l=start to doicm;
             /*if cohh>0 & cohh ^= 202 & cohh ^= 102 & cohbb=1 then dual=102;*/     /* chenged 12/4/09  will check */

         if cohh>0 & cohh^=202 & cohaa=1 & cohbb=1 then dual=102;
         if cohh>0 & cohh ^= 202 & cohh ^= 102  & mbb=1 then  dual=202;
         if cohh>0 & cohh ^= 203 & cohh ^= 103 & cohcc=1 then dual=103;
         if cohh>0 & cohh ^= 203 & cohh ^= 103 & mcc=1 then   dual=203;
         if cohh>0 & cohh ^= 204 & cohh ^= 104 & cohdd=1 then dual=104;
         if cohh>0 & cohh ^= 204 & cohh ^= 104 & mdd=1 then   dual=204;
         if dual>0 & cohh>0 & cohh ^=dual then cohh=dual;
         if dual>0 then chkdual=1;

  end;
 /* Mar_partner_Link;  */

  do l=1 to doicm;
  if dual <0 then do;
         if cohdd=1 | mdd=1 then link=p4;
         if cohcc=1 | mcc=1 then link=p3;
         if cohbb=1 | mbb=1 then link=p2;
         if cohaa=1 | maa=1 then link=p1;
   end;

  else if dual>0 then do;
         if cohaa=1 | maa=1 then link=p1;
         if cohbb=1 | mbb=1 then link=p2;
         if cohcc=1 | mcc=1 then link=p3;
         if cohdd=1 | mdd=1 then link=p4;
  end;

  countP=0;

if p1>1400 & p2=-4 then countP= 1;
     else if 0 <p1<1400 & p2=-4 then countP= 2;

      else if p1>1400 & p2>1400 & p3=-4 then  countP=4;
        else if (0<P1<1400 & p2>1400 /*| p1> 1400 & 0<p2<1400 */) & p3=-4 then countP=5;
          else if  0<p1<1400 & 0<P2<1400 & P3=-4 THEN countP=6;
        else if (p1>1400 & p2>1400 & 0<p3<1400
            | 0<p1<1400 &  p2>1400 & p3>1400
            | p1>1400 & 0<p2<1400 & p3>1400) then countP=7;
         else if ( p1>1400 & 0<p2<1400 & 0<p3<1400
                | 0<p1<1400 & P2>1400   & 0<p3<1400)  then countP=8;
            else    if  0<p1<1400 & 0<p2<1400 & p3>1400  then countP=9;
            else    if  0<p1<1400 & 0<p2<1400 & 0<p3<1400 then countP=10;
            else    if  p1>1400 & p2>1400 & p3>1400 then countP=11;

do p=1 to 4;
  do t=1 to 4;
    if slink(t)= par(p) then count_PN=1;
   else count_PN=0;
  end;
end;

  if  countp in (5 6)  & (cohbb=1 | mbb=1) & dual<=0  then link=p2;
  if  countp in (7)  & (cohcc=1 | mcc=1) then link=p3;
  if  countP in (9 ) & cohcc=1 then link=p3;
  if  countp in (11) & (cohcc=1 | mcc=1) then link=p3;
  end;

  nump13=0;  nums13=0;
  nump13=precoh_ttl;  nums13=premar_ttl;
  if (nump13=. | nump13<0) then nump13=0;
  if (nums13=. | nums13<0) then nums13=0;
  numR13=max(nump13,nums13);

  /* Add the parters & spouses from round 1 to round 14*/

  do l=start to doicm;
     if cohh>0 & 100<cohh<200 then cohh=cohh+nump13;
     else if cohh>200 then cohh=cohh+nums13;
     if dual>0 & numR13>0 then dual=dual+numR13;
  end;

  /**Find the number of partners & spouses in round 14;*/

  do l=start to doicm;
  if 100 lt cohh lt 200 then r14pt=cohh-100;
  if cohh gt 200 then r14sp=cohh-200;
  end;

  /* Stop cohabitation before dli */
 flagpcount=0;
if  countP=5 & cemca1<start then flagpcount=1;   /* added Round 9*/

if 100 lt cohhR13 lt 200 & flagp=1
  then do;
     do l=start to doicm;
       if 100 lt cohh lt 200 & r14pt=min(of r14pt169-r14pt378) & flagpcount =0 then  cohh=cohhR13;
           else if 100 lt cohh lt 200 then cohh=cohh-1;
             if   100 lt cohh lt 200 & countP in (6 ) & cohh>precoh_ttl+100 then cohh=cohh-2;  /* R14    3 case */
                if 100 lt cohh lt 200 &  countP in (4, 11) then cohh=cohhR13;
                         else if 100 lt cohh lt 200 &  countP =9 & cohh>cohhR13 then cohh=cohhR13+1;
                           if cohh gt 200 & r14sp=min(of r14sp169-r14sp378) & flagpcount =0  then cohh=200+(cohhR13-100) ;

                             else if cohh gt 200 & dlimarstat>6 & countP in (6 , 10) & count_PN=1 then cohh=200+(cohhR13-100)+1;
                         else if cohh gt 200 & dlimarstat>6 & 0<p1<1400 & count_PN=0
                      then cohh=200+(cohhR13-100)+2  ;
                 else if cohh gt 200   then cohh=cohh-1 ;
              if 100 lt dual lt 200 &  r14pt=min(of r14pt169-r14pt378) then dual=cohhR13;
            else if 100 lt dual lt 200 then cohh=dual-1;
          if dual gt 200 &  r14sp=min(of r14sp169-r14sp378) then dual=200+(cohhR13-200);
         else if dual gt 200 then dual=dual-1;
     end;
  end;

  if cohhR13>200 & flagp=1  then do;

    do l=start to doicm;
        if cohh gt 200 &  r14sp=min(of r14sp169-r14sp378) &  flagpcount =0 then cohh=cohhR13;
          else if cohh gt 200 then cohh=cohh-1;
            else if cohh>200 & countP=5 & m45002=1 then cohh=cohh+1;   /*  R14  */

          if 100 lt cohh lt 200  & r14pt=min(of r14pt169-r14pt378) & (flagpcount =0 | countP in (6 , 10)) & nump13>0
            then cohh=100+nump13;
              else if 100 lt cohh lt 200 then cohh=cohh-1;
                        if 100 lt cohh lt 200 & countP in (5 8 9) /* R14*/
                              then cohh=nump13+1+100;
                                   else if 100 lt cohh lt 200 & countP=7 then cohh=nump13+2+100;
                   if dual gt 200 & r14sp=min(of r14sp169-r14sp378)  then dual=cohhR13;
                else if dual gt 200 then dual=dual-1;
              if 100 lt dual lt 200 &  r14pt=min(of r14pt169-r14pt378) then
            dual=100+(cohhR13-200);
         else if 100 lt dual lt 200 then dual=dual-1;
     end;
  end;

  do l =start to doicm;

  if (dual=101 | dual=102 | dual=103 | dual=104 ) then r14dual=1;
  else if cohh=101 & r14dual ^= 1 then r14dual=0;
  else if cohh=102 & r14dual ^= 1 then r14dual=0;
  else if cohh=103 & r14dual ^= 1 then r14dual=0;
  else if cohh=104 & r14dual ^= 1 then r14dual=0;
  else if cohh=105 & r14dual ^= 1 then r14dual=0;
  else if cohh=106 & r14dual ^= 1 then r14dual=0;
  else if cohh=107 & r14dual ^= 1 then r14dual=0;
  else if cohh=108 & r14dual ^= 1 then r14dual=0;
  else if cohh=201 & r14dual ^= 1 then r14dual=0;
  else if cohh=202 & r14dual ^= 1 then r14dual=0;
  else if cohh=203 & r14dual ^= 1 then r14dual=0;
  else if cohh=204 & r14dual ^= 1 then r14dual=0;
  else if r14dual ^= 1 & r14dual ^= 0 then r14dual=-4;
  end;
  if r14dual=. then r14dual=-4;

   /*Find the number of partners & spouses in round 13;*/

 do l=start to 378;
   if 100 lt cohh lt 200 then r14pt=cohh-100;
   if cohh gt 200 then r14sp=cohh-200;
 end;

  /* pick up max number of total mar & total cohh */

  nump14=max(of r14pt169-r14pt378);
  nums14=max(of r14sp169-r14sp378);
  numr14=max(nump13,nums13);
  coh_ttl=nump14;
  mar_ttl=nums14;
  if nump14=. then coh_ttl=precoh_ttl;
  if nums14=. then mar_ttl=premar_ttl;
  if p1=-4 & p2=-4 & p3=-4  then do;
  coh_ttl=precoh_ttl;
  mar_ttl=premar_ttl;
  end;

  /* Married more then once at R14. first spouse is  loop2 and secend spouse is loop3  pubid=1750 */

do l=start to doicm;
     do i=2 to 3;
            if cohh>=200+i & premar_ttl=0 & mbb=1 then do;
              cohh=cohh-1;
              mar_ttl=i;
              flagmbb=1;
            end;

           if cohh>=200+i & premar_ttl=0  & mcc=1 then do;
              cohh=cohh-1;
              mar_ttl=i;
              flagmcc=1;
           end;
      end;
 end;

 /* Added in Round 9    married only once at R14*/

do l=start to doicm;
     do i=1 to 3;
           if cohh>=200+i & premar_ttl= i-1 & flagmcc~=1 & flagmcc~=1  then do;
              cohh=200+i;
              mar_ttl=i;
           end;
     end;
 end;

flagcohh101=0;
  do l=start to doicm;
       if cohh=101 then flagcohh101=1;
    end;
       if flagcohh101=0 & precoh_ttl<1 then do;
          do l=start to doicm;
       if 101<cohh<201 & countP in (4 11)  then do;
          cohh=101;
          coh_ttl=1;
     end;
  end;
end;

  /* for  R's first time cohh & married at same time */

  do p=1 to 4; /* loop for p */
      do t=1 to 4; /* loop for t */
        if mbeg=1 &  Mar_ttl>0
            & precoh_ttl<=0  &  dlicohcm<-3 & p2=-4  then do;      /* 12-8-2011 */
              coh_ttl=0;
              cohcm=-4;
              cohy=-4;
              cohm=-4;
         end;

        if  ysp>-4 & msp>-4 then mar_ttl=1;  /* spouse lives outside of HH this is  new in round 9*/
     end;
  end;

  /* 4 cases in round 9 */

  if mar_ttl>0 & coh_ttl=0 & cohcm>-4 then do;
     cohy=-4;
     cohm=-4;
     cohcm=-4;
  end;

   if precoh_ttl>coh_ttl & coh_ttl>0 then coh_ttl=precoh_ttl;

  /** separated in previous round. Then live together again  two case in round 11     */
  /* m4350a=3 still married to this person   added  R13 */

    do p=1 to 4;
           do t=1 to 4;
                if M4350a1=3 &   mar_ttl>0 & m620=1 & (dlimarstat=5 | dlimarstat=6) & m114001 not in (3,4)   then do;
                     do l=start to doicm;
                        mars=2;
                    if mar_ttl=1 & cohh>0 & p2=-4 then cohh=200+1;
                    if link=-4 | link=.  then link=slink1;
                       marstat=4;
                       cmarstat=1;
              if  M700011Y>-4 & marstat=4 then marstat=3;
             end;
       end;
   end;
end;

    /*Spouse is missing in household Roster    add in round 9*/

  do p=1 to 4; /* loop for p */
      do t=1 to 4; /* loop for t */
        if dlimarstat=-3 and premar_ttl>0 and m620 in (-1, -2) and fstat=-4 then do;
             do  l=start to doicm;
                 marstat=dlimarstat;
                 cmarstat=dlimarstat;
                 mars=dlimarstat;
                end;
          end;
     end;
 end;

  /* Married, but living with someone else.
   We have to find out who is  spouse and who is partner if there are more then one
 loops in current round.
   10-1-06 talked with Rosella, coded marstat=4,  married spouse absent
   slink is the spouse link. only one exceptionals: spouse is live outside of
 household
  //*12-26-06   R12 added */

 matchlink=0;
  flagslink=0;
  do i=1 to 4;
     do l=start to doicm until(mars=2 & cohh=200+i);
       if mars=2 & cohh=200+i then do ;
           slink{i}=link;
            end;
      end;
  end;

  /*Spouse live outside household     add 2-9-09  */

   do i=1 to 3;
     do l=start to doicm until(mars=2 );
        if  mars=2 & cohh=. & link>-4 & slink1<=-4 & slink2<=-4 then do;
        if slink(i)<=-4 then slink(i)=link;
        end;
      end;
   end;

do i=1 to 3;
   if slink{i} =slink{i+1} then slink{i+1}=-4;
end;

do l=doicm;
    if marstat=3 then r14link=link;
end;

  /* Find partner link in R13. The ID of these partners are not spouse the spouse
 IDs */
   do i=1 to 3;
     if slink{i}=r14link & r14link>0 then matchlink=1;  /* Special edit for R13 case */
   end; /* Special edit for R13 case */

     if matchlink ne 1 & marstat=3 then flagslink=1;
     if flagslink=1 then marstat=4 ;
     if flagslink=1  & (dlim620=0 & m620=0 ) & P_ST1 ne 9 then do;  /* Special edit for R13 cases */
        marstat=-3;
        cmarstat=-3;
      do l=start to doicm;
        mars=-3;
      end;
    end;

   if flagslink=1  & dlim620=2 & m620=2 &  P_ST1=2 & m4350a1 ne 3  then do;  /* Special edit for R13 cases */
       marstat=5;
       cmarstat=2;
        do l=start to doicm;
        mars=3;
        if link=slink1 | link=slink2 | link=slink3 then link=-4;
      end;
    end;

    /* The code below is finding the missing spouse.  spouse is missing in household Roster & partner roster, Respondent is cohabiting with someone else*/

 spouse=0;
     cspouse=0;
      do t=1 to 4;
        do i=1 to 4;
              if slink{i}>0 & par{t}>0 then do;
              if par{t}=slink{i} & marstat>2  then spouse=1 ;
          end;
         end;
  end;
  if mar_ttl>0 & 2<marstat <7 & spouse =0 & slink1>0 then cspouse=1;

  /** If R's answer m620=3 in previous two Rounds, we coded Round 9 marstat status
 as divo_d*/

 if cspouse=1 and (dlim620=3 & m620=3 ) then do;
    do l=start to doicm;
      if p1=-4 then do;
        mars=4;
        marstat=8;
        cmarstat=3;
      end;
    end;
  end;

  /* Check Round 10 (if m620r8=1 | m620r8=2  and m620=3 and m620R12=3. I give status
  as 7 or 8*/

  if cspouse=1 and ((dlim620=3 )& m620=3 & p1>0 & marstat<=6) then do;
    do l=start to doicm;
         mars=4;
         marstat=7;
         cmarstat=3;
      end;
   end;

  if cspouse=1 and (dlim620=2 & m620=3 ) then do;
    do l=start to doicm;
      if p1=-4 then do;
         mars=3;
         marstat=6;
         cmarstat=2;
      end;
    end;
  end;

  /* if R's answer m620=2 in R12 and m620=2 in previous round . we coded marstat
 status   in R12 as separated. */

  if cspouse=1 and (dlim620=2 & m620=2) then do;
    do l=start to doicm;
        if p1=-4    | (m46701 ne 1 & m47001 ne 1) then do;
         mars=3;
         marstat=6;
         cmarstat=2;
           end;
    end;
  end;

  if cspouse=1 and (dlim620=2 & m620=3 & p1>0 & marstat<=6) then do;
    do l=start to doicm;
       mars=3;
       marstat=5;
       cmarstat=2;
      end;
   end;

  /* if R's answer m620=3 in R12 and m620=2 in previous round or R's R's deny
 marriage. we coded marstat status

     in R12 as -3. We need to rechecked these cases in Round 11*/
  if( cspouse=1 and ((dlim620<2 & m620=3) | m620=0 ) & dlimarstat ne 5 and dlimarstat ne 6
  | cspouse=1 & m620 in (-1,-2)
  | cspouse=1 & dlimarstat=-3 & m620 =2 & p1=-4)
    then do;
    do l=start to doicm;
          mars=-3;
          marstat=-3;
          cmarstat=-3;
         if link=<-3 then link=-3;
     end;
  end;

  if cspouse=1 and ((dlim620<2 & dlim620 ne 1 | dlimarstat=-3)) & m620=2 then do;
    do l=start to doicm;
        if p1>0 & (m47001=1 | m46701=1) then do;
           do l=start to doicm;
          mars=-3;
          marstat=-3;
          cmarstat=-3;
          if link=<-3 then link=-3;
         end;
    end;
  end;
 end;

   /* Married but living with someone else. I fill in with spouse link if spouse
 link is missing */

  do l=start to doicm;
    do i=1 to 4;
       if (3<=marstat<=4) & (3<=dlimarstat<=4) then do;
          if link=. & slink{i}>0 & slink2=-4 then do; /* 1-25-2012 R14  */
             link=  slink{i};
            if slink1>0 & slink2>0 & slink2<1400 then link=slink2;   /* 1-25-2012 R14  */
            else if slink2>0 & slink3>0 then link=slink3;
               end;
         end;
     end;
  end;

  /* separated then divo_d    */

  if (M540011=3 | m7900111=3) & M114001=4 | (M540021=3 | m7900211=3) & M114002=4
 then do;
  do l=start to csmsa1-1;
  if mars=2 then mars=3;
  if link>0 then link=-4;
  if cohh>0 then cohh=-4;
  end;
end;

  /* Never married, Reoprted legal separation data. Recode as break up   10-23-07*/
  if (m620=0 ) & mar_ttl=0 & premar_ttl=0 then do;
  if marstat=6 then do;
     marstat=2;
     cmarstat=0;
  do l=start to doicm;
  if mars=3 then mars=0;
    end;
   end;
  end;

  count620=0;
  do i=11 to 12;
    if m620r(i)=1  then do;
    count620=count620+1;
    if count620=2 & m620>=1 & mar_ttl<=0 then flag620=1;
    end;
  end;
  if m620=1 & mar_ttl=0  & count620>=1 then case620=1;   /* needs to check r13 */

  /* for round 12 only */
  if dlimarstat=4 & flagp=1  & marstat<5 then do;
   do l=start to doicm;
   if  mars=2 & 100=<cohh<200 & link<1400 then chk1=1;
   if  mars=0 | mars=1 | mars=. then chk2=1;
    end;
  end;

  /* Divoeced at dli, then remarried with previous spouse */
if  dlimarstat in (7,8) & ( (p1=slink1 | p1=slink2 ) & p1>0 | (p2=slink1 | p2=slink2) & p2>0 ) & mar_ttl=premar_ttl & marstat<7 &( m7900111=1 | m45001=1) then do;
   do l=start to doicm;
   if cohh>0 then cohh=cohh+1;
   end;
   mar_ttl=mar_ttl+1;
   end;

  if pubid=6204 then do;
    do  l=start to 361;
        mars=3;
    end;
  end;

if pubid=597 then do;  /* two new partners, one partner married */
 coh_ttl=1;
 end;

  if int_y=-5 then do;
  mar_ttl =-5;
  marstat =-5;
  cmarstat=-5;
  coh_ttl =-5;
  marm=-5;
  mary=-5;
  marcm =-5;
  cohcm=-5;
  cohm=-5;
  cohy=-5;
  r14dual=-5;
  end;

  do l=start to doicm;
  if dual=. then dual=-4;
  if mars=. then mars=-4;
  if link=. then link=-4;
  if cohh=. then cohh=-4;
  end;

  if doicm=-5 then do;
    do l=start to doicm;
       mars=-4;
       cohh=-4;
       dual=-4;
       link=-4;
    end;
  end;

   do l=169 to 378;
      if mars=. then mars=-4;
      if link=. then link=-4;
      if cohh=. then cohh=-4;
   end;

if pubid = 7202 then do;
   do l=start to 365;
    if mars<2 then mars=-3;
     if 0<cohh<200 then cohh=101;
     coh_ttl =1;
     cohcm=360;
     cohm=12;
     cohy=2009;
   end;
 end;

 if pubid in ( 5201) then   mar_ttl=1;
 if pubid= 7218 then do; /* partner variable is missing */
 cohcm =-4;
 cohm=-4;
 cohy=-4;
 end;

/*First cohabitation doesn't match up the MAR_COHABITATION array  from round11 to round 12
diffcohh     cvc_diff_cohabitation=1   1st cohabitation date does not match up the MAR_COHABITATION array
diffmar      cvc_diff_marriage=1       1st marriage data does not match up the MAR_COHABITATION array*/
/*First cohabitation doesn't match up the marriage Mar_cohh_array in round 11 */

 checkfir=0;
 checkfir_M=0;
 checkmar=0;
 checkcohh=0;
 type1=0;
 type2=0;

if dlicohcm<-3 & cohcm>-4 then do;
  do l=start to doicm until (100<cohh<200 );
  if cohh>0 then checkcohh=l;
  end;
  if cohcm>0 & checkcohh>0 & cohcm ne checkcohh then checkfir=1;

if checkfir=1 then do;
  if checkcohh = cohcm+1 then type1=1;  /* one month different */
  if checkcohh > cohcm+1 then type1=2; /* more then one month different */
  if checkcohh < cohcm   then type1=3;
 end;
end;

n=12;

if dlimarcm<-3 & marcm>-4 then do;
     do l=start to doicm until (mars=2);
      if mars=2 then checkmar=l;
     end;
     if marcm>0 & checkmar>0 & marcm ne checkmar then checkfir_M=1;
     if checkfir_M=1 then do;

   if checkmar = marcm+1  then type2=1;  /* one month different */
   if checkmar  > marcm+1 then type2=2; /* more then one month different */
   if checkmar  < marcm   then type2=3;
  end;
end;

diffcohh=-4;
diffmar=-4;

if diffbothr13 =1 | checkfir=1   then diffcohh=1;
if diffMARr13  =1 | checkfir_M=1 then diffmar=1;

/*divorceM     CVC_first_divorce_date_M   Month of first divorce
divorceY       CVC_first_divorce_date_Y   year of first divorce
divor_CM       CVC_first_divorce_month    continuous month of first divorce */

/*  rename all cataloges of variables equal 4:  divorced */

if m716jb1M >-4 then m716jb1=4;
if m716jb2M >-4 then m716jb2=4;
/*if m716jb3M >-4 then m716jb3=4; */
if m716wb1m>-4  then m716w1 =4;
if m716wb2m>-4  then m716w2 =4;
if m717j1=3    then m717j1 =4;
if m4350a1=1    then m4350a1=4;
if m4350a2=1    then m4350a2=4;
if m13250m>-4   then m13225 =4;

/* Redefine arrays:   define two dimension arrays */

divo_11=m716jb1;     divo_12=m716jb2;   /*divo_13=m716jb3;*/   divo_14=m716w1;     divo_15=m716w2;     divo_16=m717j1;
divoM_11=m716jb1m;   divoM_12=m716jb2m; /*divoM_13=m716jb3m; */ divoM_14=m716wb1m;  divoM_15=m716wb2m; divoM_16=m717jb1m;
divoY_11=m716jb1y;   divoY_12=m716jb2y; /*divoY_13=m716jb3y;*/ divoY_14=m716wb1y;  divoY_15=m716wb2y;  divoY_16=m717jb1y;

divo_21=m540011;     divo_22=m540012;     divo_23=m540013;    divo_24=m540014;   divo_25=m540021;       divo_26=m540022;
divoM_21=m560011m;   divoM_22=m560012m;   divoM_23=m560013m;  divoM_24=m560014m; divoM_25=m560021m;     divoM_26=m560022m;
divoY_21=m560011y;   divoY_22=m560012y;   divoY_23=m560013y;  divoY_24=m560014y; divoY_25=m560021y;     divoY_26=m560022y;

divo_31=m7900111;    divo_32=m7900112;    /*divo_33=m7900113;   */  /* divo_34=m7900114;   */ divo_35 =m7900211;  divo_36 =m7900212;
divoM_31=m8100111m;  divoM_32=m8100112m;  /*divoM_33=m8100113m; */  /* divoM_34=m8100114m; */ divoM_35=m8100211m; divoM_36=m8100212m;
divoY_31=m8100111y;  divoY_32=m8100112y;  /*divoY_33=m8100113y; */  /* divoY_34=m8100114y;*/  divoY_35=m8100211y; divoY_36=m8100212y;

divo_41 =m9800111;    /*divo_42=M9800112;    */  divo_43=m114001;   divo_44=m114002;    divo_45=m114003;     divo_46=m13225;
divoM_41=m10000111m;  /*divoM_42=M10000112M; */ divoM_43=m117001m; divoM_44=m117002m;   divoM_45=m117003m;   divoM_46=m13250m;
divoY_41=M10000111Y;  /*divoY_42=M10000112Y;*/  divoY_43=m117001y; divoY_44=m117002y;   divoY_45=m117003y;   divoY_46=m13250y;

divo_51=m4350a1;      divo_52=m4350a2;       divo_53=m4350a1;
divoM_51=m4360a1m;    divoM_52=m4360a2m;     divoM_53=m4370a1m;
divoY_51=m4360a1y;    divoY_52=m4360a2y;     divoY_53=m4370a1y;

/*Define arrays  */

array divo_   (5,6)    divo_11 - divo_16      divo_21- divo_26      divo_31- divo_36       divo_41- divo_46      divo_51- divo_56;
array divo_M  (5,6)    divoM_11 - divoM_16    divoM_21 - divoM_26   divoM_31 - divoM_36    divoM_41 - divoM_46   divoM_51 - divoM_56;
array divo_Y  (5,6)    divoY_11- divoY_16     divoY_21 - divoY_26   divoY_31 - divoY_36    divoY_41 - divoY_46   divoY_51 - divoY_56;
array divo_cm (5,6)    divocm_11 - divoCM_16  divocm_21 - divocm_26 divocm_31 - divocm_36  divocm_41 - divocm_46 divocm_51 - divocm_56;

firdivo_cmR14=-4;    /* r14 variables */
firdivo_MR14 =-4;
firdivo_YR14 =-4;
end_marR14   =-4;

divorceM=-4;        /* r1-r13 cvc variables*/
divorceY=-4;
divor_CM=-4;

/*end_firmarR13 divo_MR13  divo_YR13 divo_CMR13*/
do k=1 to 5;
    do i=1 to 6;
          if divo_(k,i)=4 & divo_M(k,i)>0 & divo_Y(k,i)>0 then do;
             divo_cm(k,i) = (divo_Y(k,i)-1980)*12+ divo_M(k,i);
                firdivo_cmR14=min(of divocm_11 - divoCM_16  divocm_21 - divocm_26  divocm_31 - divocm_36  divocm_41 - divocm_46 divocm_51 - divocm_56);
              end;
      end;
  end;

if firdivo_cmR14>0 then do;
            do i=384 to 216 by -12;    /* 384 Dec 2011  */   /*  348 Dec 2008  */
                 fir=i;
                  if  fir-11<=firdivo_CMR14 <=fir then do;
                      firdivo_MR14=firdivo_cmR14-(fir-12);              /* 10/05= 310  10=310-(312-12) */
                      firdivo_YR14=(firdivo_cmR14-firdivo_MR14)/12+1980;
                  end;
          end;
end;

if firdivo_cmR14=-4 then do;
 do k=1 to 5;
    do i=1 to 6;
           if divo_(k,i)=4 & (divo_M(k,i) in ( -1, -2,-3 ) | divo_y(k,i) in (-1,-2,-3)) then do;
           divo_cm(k,i)=-3;
                   firdivo_mR14=divo_m(k,i);
                   firdivo_YR14=divo_Y(k,i);
                   if firdivo_mR14 in (-1 -2,-3) then firdivo_mR14=-3;
                   if firdivo_YR14 in (-1 -2,-3) then firdivo_YR14=-3;
                   firdivo_cmR14=-3;
         end;
     end;
   end;
end;

/* find widowed r1-R14 */
count_w=0;
do i=1 to 12;
if  m620r(i)=4   then count_w=count_w+1;
end;

if m620=4 & mar_ttl>0 & count_w=0  then do;
    divor_CM= -3;
    divorceM=-3;
    divorceY=-3;
    end_mar=2;
  end;

if  cspouse=1 and (dlim620=3 & m620=3 ) & marstat>6 & divo_CMR13=-4 then do;
    firdivo_cmR14=-3;
    firdivo_mR14=-3;
    firdivo_YR14=-3;
    end_marR14=1;
    end_mar=1;
end;

if firdivo_cmR14>-4 & divo_CMR13<=-4 then do;
    divor_CM= firdivo_cmR14;
    divorceM=firdivo_mR14;
    divorceY=firdivo_YR14;
    end_marR14=1;
    end_mar=1;
end;

/* Married two times without divo_ data with first spouse.
Talked to Rosella. code -3 and give ID's to FRANK  */
 /*  Death of spouse  */
 /* Get an annulment */

if  (premar_ttl=2 | mar_ttl=2) & divo_CMR13=-4 & firdivo_cmR14=-4 & count_w=0

   then do;
     divor_CM=-3;
     divorceM=-3;
     divorceY=-3;
     end_mar=3;
 end;

 if firdivo_cmR14 >-4 & ( m4350a1 =2 |  m4350a2 =2) then end_mar=3;

 IF  (premar_ttl=2 | mar_ttl=2) & firdivo_cmR14>-4 & divo_CMR13>-4 &  divo_CMR13 ~= firdivo_cmR14
     then check_divo=1; /* divorced twice */
 if check_divo=1 then do;
    divor_CM= divo_CMR13;
    divorceM=divo_MR13;
    divorceY=divo_YR13;
    end_mar=end_marR13;
end;

if firdivo_cmR14=-4 & divo_CMR13>-4 then do;

    divor_CM= divo_CMR13;
    divorceM=divo_MR13;
    divorceY=divo_YR13;
    end_mar=end_marR13;
end;

if  divo_CMR13>-4 then do;
    divor_CM= divo_CMR13;
    divorceM=divo_MR13;
    divorceY=divo_YR13;
    end_mar=end_marR13;
end;

if end_marR13=3 & end_mar=. then end_mar=end_marR13;

/* Report difference divorce data with same spouse */
if divo_CMR13>-4 & firdivo_cmR14>-4 &  divo_CMR13 ~= firdivo_cmR14  then check_divo=2;
if check_divo=2 then do;
    divor_CM= divo_CMR13;
    divorceM=divo_MR13;
    divorceY=divo_YR13;
    end_mar=end_marR13;

        if( 0<divor_CM<=marcm | 0<divor_CM<=dlimarcm ) &  firdivo_cmR14 >-4 then do;
    divor_CM= firdivo_cmR14;
    divorceM=firdivo_mR14;
    divorceY=firdivo_YR14;
    end;
end;

if divor_CM<-3 then do;
    divor_CM=-4;
    divorceM=-4;
    divorceY=-4;
    end_mar=-4;
 end;

 if pubid=159 then do;
   do l=367 to 370 ;
   cohh=-4;
   link=-4;
   end;
   do l=358 to 361;
   mars=-3;
   end;
end;

 if pubid=7402 then do;   /* bad divorce date */
    marstat=8;
    cmarstat=3;
  do l=start to doicm;
  mars=4;
  link=-4;
  end;
 end;

if pubid=159 then do;
  do l=360 to 361;
     mars=4;
  end;
end;

/* Missing marriage data,  They are separated */
  if pubid= 563 then do;
    marm=-3;
    mary=-3;
    marcm=-3;
    mar_ttl=1;

   do l=364 to doicm;
   if mars in (1,0) then mars=2;
   if cohh=101 then cohh=201;
   if link=-4 then link=p1;
   end;
end;

if pubid in(1397 3547  4039 4594) then mar_ttl=2;

/* Reported divorce data no marriage data report, code first CV marriage as -3 */

if (firdivo_cmR14>-4 |  divo_CMR13>-4 | divor_CM>-4) & (mar_ttl=0 | marcm=-4) then flagM=1;

do l=start to doicm;
if  mars=0 &  (dlimarstat >2 | dlimarstat=-3) then flagmars=1;
if  flagmars=1  & m4350a1 ^=2 then mars=2;
if (mars=1 or mars=2) & link=-4 then flagmars=2;
end;

if int_y=-5 then do;
   cohm=dlicohm;
   cohy=dlicohy;
   cohcm=dlicohcm;
   marm=dlimarm;
   mary=dlimary;
   marcm=dlimarcm;
end;

endsas;