NLSY79 Appendix 8: Highest Grade Completed & Enrollment Status Variable Creation

National Longitudinal Survey of Youth - 1979 Cohort

NLSY79 Appendix 8: Highest Grade Completed & Enrollment Status Variable Creation

 

Introduction

The series of programming statements contained in this appendix were used in the standard computations for the created Highest Grade Completed (HGC) from 1990-2010 and Enrollment Status as of May 1st Survey Year variables from 1990-2006.

In addition to the standard created variables, revised versions of the HGC and Enrollment Status variables (1979-2010 survey years and 1979-2006 survey years, respectively) have been added to the NLSY79 main data file. The general sources of error in the standard created variables were:

  • grade "reversals", in which a respondent completed a lower grade in a later year, rather than staying in the same grade or advancing: The programs included below did not account for these cases, the largest source of which have been respondents enrolled in college;
  • respondents with incomplete or ambiguous school information, preventing the computation in a given year of a HGC or Enrollment Status variable (a problem which can then continue through subsequent years, even if the respondent reported attending school in later survey years).

Decision rules for adjustments reflected in the revised variables include:

  • Cases with grade reversals were coded as the highest grade completed previously reported by the respondent;
  • A minimum HGC code of 12 was assigned to cases in which no high school diploma or GED had been received, but some college attendance was reported;
  • An HGC code of 16 was assigned to cases in which a four-year degree had obviously been earned in 5 or more years;
  • Cases in which the highest grade completed was reported as "ungraded" were assigned the previous highest grade completed reported by the respondent;
  • HGC values were evaluated in comparison to the May 1st of survey year date and corrected if necessary;
  • Cases in which the longitudinal record is highly erratic and HGC could not be computed or revised reliably were assigned a code of "-3" (invalid missing).

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of May 1, 1990

/*  THE FOLLOWING SPSS CODE IS APPLIED TO THE DATA BEFORE THE PLI PROGRAM */ 
/*  IS EXECUTED.  THE PURPOSE OF THE CODE IS TO APPROPRIATELY RECODE      */ 
/*  SELECTED 1979 AND 1980 VARIABLES.                                     */ 
/*                                                                        */ 
/*  DO IF (R2283 EQ 0 OR R2282 EQ 0)                                      */ 
/*  COMPUTE DLEMO79=R2287                                                 */ 
/*  COMPUTE DLEYR79=R2288                                                 */ 
/*  ELSE                                                                  */ 
/*  COMPUTE DLEMO79=R169                                                  */ 
/*  COMPUTE DLEYR79=R170                                                  */ 
/*  END IF                                                                */ 
/*  DO IF (R4052 GT 0 AND R2283 NE 0 AND R2282 NE 0)                      */ 
/*  COMPUTE DLEMO80=R2287                                                 */ 
/*  COMPUTE DLEYR80=R2288                                                 */ 
/*  END IF                                                                */ 
/*  DO IF (R2275 EQ 0 OR R2276 EQ 0)                                      */ 
/*  COMPUTE GRADE79=R2277                                                 */ 
/*  ELSE                                                                  */ 
/*  COMPUTE GRADE79=R2286                                                 */ 
/*  END IF                                                                */ 
/*  DO IF (R2280 GE 0)                                                    */ 
/*  COMPUTE HGCS79=R2280                                                  */ 
/*  ELSE                                                                  */ 
/*  COMPUTE HGCS79=R173                                                   */ 
/*  END IF                                                                */ 
/*  IF (R2276 EQ 0 AND R2286 GT 0) R156=1                                 */
/**************************************************************************/
 
 DCL 1 INREC7989,                                                            
 
     2 CURAT(79:89)  PIC '------9',
          /*  R(  156.) R( 2285.) R( 4168.) R( 6639.) R( 9053.) R(12052.)  */
          /*  R(16045.) R(19050.) R(23059.) R(25084.) R(29075.)            */
 
     2 DIP(79:89)    PIC '------9',
          /*  R(  183.) R( 2300.) R( 4182.) R( 6653.) R( 9067.) R(12066.)  */
          /*  R(16059.) R(19061.) R(23070.) R(25095.) R(29086.)            */
 
     2 DLEMO(79:89)  PIC '------9',
          /*  DLEMO79   DLEMO80   R( 4170.) R( 6641.) R( 9055.) R(12054.)  */
          /*  R(16047.) R(19052.) R(23061.) R(25086.) R(29077.)            */
 
     2 DLEYR(79:89)  PIC '------9',
          /*  DLEYR79   DLEYR80   R( 4171.) R( 6642.) R( 90546) R(12055.)  */
          /*  R(16048.) R(19053.) R(23062.) R(25087.) R(29078.)            */
 
     2 GRADE(79:89)  PIC '------9',
          /*  GRADE79   R( 2286.) R( 4169.) R( 6640.) R( 9054.) R(12053.)  */
          /*  R(16046.) R(19051.) R(23060.) R(25085.) R(29076.)            */
 
 
     2 HGA(79:89)    PIC '------9',
          /*  R(  172.) R( 2291.) R( 4173.) R( 6644.) R( 9058.) R(12057.)  */
          /*  R(16050.) R(19055.) R(23064.) R(25089.) R(29080.)            */
 
     2 HGC(79:89)    PIC '------9',
          /*  R( 2167.) R( 4064.) R( 6189.) R( 8982.) R(11450.) R(15202.)  */
          /*  R(18909.) R(22580.) R(24454.) R(28711.) R(30748.)            */
 
     2 HGCS(79:89)   PIC '------9',
          /*  HGCS79    R( 2292.) R( 4174.) R( 6645.) R( 9059.) R(12058.)  */
          /*  R(16051.) R(19056.) R(23065.) R(25090.) R(29081.)            */
 
     2 INTMO(79:89)  PIC '------9',
          /*  R( 1725.) R( 3292.) R( 5307.) R( 8099.) R(10457.) R(14275.)  */
          /*  R(17946.) R(21562.) R(23657.) R(27425.) R(29861.)            */
 
     2 WEIGHT(79:89) PIC '9999999';
          /*  R( 2161.) R( 4052.) R( 6146.) R( 8967.) R(11444.) R(15196.)  */
          /*  R(18902.) R(22573.) R(24445.) R(28700.) R(30738.)            */
 
 DCL 1 INREC90,
     2 WEIGHT_90    PIC '9999999',  /*  R(34002.)  */
     2 SCHOOL_90,
       5 ASLI_90    PIC '------9',  /*  R(31070.)  */
       5 CURAT_90   PIC '------9',  /*  R(31096.)  */
       5 DIP_90     PIC '------9',  /*  R(31107.)  */
       5 DLEMO_90   PIC '------9',  /*  R(31098.)  */
       5 DLEYR_90   PIC '------9',  /*  R(31099.)  */
       5 GRADE_90   PIC '------9',  /*  R(31097.)  */
       5 HGA_90     PIC '------9',  /*  R(31101.)  */
       5 HGCS_90    PIC '------9',  /*  R(31102.)  */
       5 INTMO_90   PIC '------9',  /*  R(33025.)  */
       5 HAVEDIP_90 PIC '------9',  /*  R(31106.)  */
       5 ATTCOL_90  PIC '------9';  /*  COMPUTE ATTCOL_91=0                */
                                    /*  IF R(31103.)>3 THEN ATTCOL_91=1    */
       5 GRA_90     PIC '------9',  /*  COMPUTE GRA_91=-3                  */
                                    /*  IF R(31096.)=1                     */
                                    /*  THEN GRA_91=R(31097.)              */
                                    /*  ELSE IF R(31096.)=0                */
                                    /*  THEN GRA_91=R(31101.)              */
                                    /*  ELSE IF R(31070.)=0                */
                                    /*  THEN GRA_91=-4                     */
 
 /*  CREATION OF HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS      */
 /*  AS OF 5-1-90                                                   */
 
    HGC_90=-4;
    ENROLL_90=-4;
    DO I=80 TO 89;
       IF WEIGHT(I)=0 THEN DO;
          HGCS(I)=-5;
          GRADE(I)=-5;
       END;    
    END;
    IF WEIGHT_90=0 THEN DO;
       HGCS_90=-5;
       GRADE_90=-5;
       ENROLL_90=-5;
       HGC_90=-5;
    END;
 
  IF WEIGHT_90>0 THEN DO;
    IF ASLI_90=0 & (HAVEDIP_90=-4 ! HAVEDIP_90=0) THEN DO;
        IF WEIGHT(89)>0 THEN DO;
           IF INTMO(89)>=5 & (CURAT(89)=1 ! (DLEMO(89)>=5 & DLEYR(89)=89)) &
              HGCS(89)>HGC(89) THEN HGC_90=HGCS(89);
           ELSE HGC_90=HGC(89);
        END;
        ELSE IF WEIGHT(88)>0 THEN DO;
           IF INTMO(88)>=5 & (CURAT(88)=1 ! (DLEMO(88)>=5 & DLEYR(88)=88)) &
              HGCS(88)>HGC(88) THEN HGC_90=HGCS(88);
           ELSE HGC_90=HGC(88);
        END;
        ELSE IF WEIGHT(87)>0 THEN DO;
           IF INTMO(87)>=5 & (CURAT(87)=1 ! (DLEMO(87)>=5 & DLEYR(87)=87)) &
              HGCS(87)>HGC(87) THEN HGC_90=HGCS(87);
           ELSE HGC_90=HGC(87);
        END;
        ELSE IF WEIGHT(86)>0 THEN DO;
           IF INTMO(86)>=5 & (CURAT(86)=1 ! (DLEMO(86)>=5 & DLEYR(86)=86)) &
              HGCS(86)>HGC(86) THEN HGC_90=HGCS(86);
           ELSE HGC_90=HGC(86);
        END;
        ELSE IF WEIGHT(85)>0 THEN DO;
           IF INTMO(85)>=5 & (CURAT(85)=1 ! (DLEMO(85)>=5 & DLEYR(85)=85)) &
              HGCS(85)>HGC(85) THEN HGC_90=HGCS(85);
           ELSE HGC_90=HGC(85);
        END;
        ELSE IF WEIGHT(84)>0 THEN DO;
           IF INTMO(84)>=5 & (CURAT(84)=1 ! (DLEMO(84)>=5 & DLEYR(84)=84)) &
              HGCS(84)>HGC(84) THEN HGC_90=HGCS(84);
           ELSE HGC_90=HGC(84);
        END;
        ELSE IF WEIGHT(83)>0 THEN DO;
           IF INTMO(83)>=5 & (CURAT(83)=1 ! (DLEMO(83)>=5 & DLEYR(83)=83)) &
              HGCS(83)>HGC(83) THEN HGC_90=HGCS(83);
           ELSE HGC_90=HGC(83);
        END;
        ELSE IF WEIGHT(82)>0 THEN DO;
           IF INTMO(82)>=5 & (CURAT(82)=1 ! (DLEMO(82)>=5 & DLEYR(82)=82)) &
              HGCS(82)>HGC(82) THEN HGC_90=HGCS(82);
           ELSE HGC_90=HGC(82);
        END;
        ELSE IF WEIGHT(81)>0 THEN DO;
           IF INTMO(81)>=5 & (CURAT(81)=1 ! (DLEMO(81)>=5 & DLEYR(81)=81)) &
              HGCS(81)>HGC(81) THEN HGC_90=HGCS(81);
           ELSE HGC_90=HGC(81);
        END;
        ELSE IF WEIGHT(80)>0 THEN DO;
           IF INTMO(80)>=5 & (CURAT(80)=1 ! (DLEMO(80)>=5 & DLEYR(80)=80)) &
              HGCS(80)>HGC(80) THEN HGC_90=HGCS(80);
           ELSE HGC_90=HGC(80);
        END;
        ELSE DO;
           IF INTMO(79)>=5 & (CURAT(79)=1 ! (DLEMO(79)>=5 & DLEYR(79)=79)) &
              HGCS(79)>HGC(79) THEN HGC_90=HGCS(79);
           ELSE HGC_90=HGC(79);
        END;
        IF HGC_90>=12 THEN ENROLL_90=4;
        ELSE IF HGC_90>=0 THEN ENROLL_90=1;
     END;
     ELSE IF ASLI_90=1 THEN DO;
        IF HGCS_90<=0 THEN DO;
           IF CURAT_90=1 & GRADE_90>=1 THEN DO;
              HGC_90=GRADE_90-1;
              IF HGC_90>=12 THEN ENROLL_90=3;
              ELSE ENROLL_90=2;
           END;
           ELSE IF CURAT_90=0 & HGA_90>=1 THEN DO;
              IF DLEYR_90<90 ! DLEMO_90<5 THEN DO;
                 HGC_90=HGA_90;
                 IF HGC_90>=12 THEN ENROLL_90=4;
                 ELSE ENROLL_90=1;
              END;
              ELSE DO;
                 HGC_90=HGA_90-1;
                 IF HGC_90>=12 THEN ENROLL_90=4;
                 ELSE ENROLL_90=1;
              END;
           END;
        END;
        ELSE DO;
           IF HGCS_90=HGA_90 ! HGCS_90=GRADE_90 THEN DO;
              IF (DLEYR_90=90 & DLEMO_90>=5) ! (INTMO_90>=5 &
                 CURAT_90=1) THEN DO;
                 HGC_90=HGCS_90-1;
                 IF HGC_90>=12 THEN ENROLL_90=3;
                 ELSE ENROLL_90=2;
              END;
              ELSE HGC_90=HGCS_90;
           END;
           IF HGCS_90=HGA_90-1 ! HGCS_90=GRADE_90-1 THEN
              HGC_90=HGCS_90;
           ELSE IF (HGCS_90<HGA_90 & HGA_90>0 & HGA_90<20) !
              (HGCS_90<GRADE_90 & GRADE_90>0 & GRADE_90<20) THEN
              HGC_90=HGCS_90;
           IF ENROLL_90=-4 & CURAT_90=1 & HGC_90>=0 THEN DO;
              IF HGC_90>=12 THEN ENROLL_90=3;
              ELSE ENROLL_90=2;
           END;
           IF ENROLL_90=-4 & CURAT_90=0 & HGC_90>=0 THEN DO;
              IF HGC_90>=12 THEN ENROLL_90=4;
              ELSE ENROLL_90=1;
           END;
        END;
     END;
     IF ((HGC_90=10 ! HGC_90=11) & (HAVEDIP_90=1 ! ATTCOL_90=1)) !
       (DIP_90=2 & HGC_90<12) ! (HGC_90=-4 & (DIP_90=1 ! DIP_90=3))
        THEN DO;
        HGC_90=12;
        IF ENROLL_90>0 THEN ENROLL_90=5-ENROLL_90;
        ELSE IF CURAT_90=1 ! (DLEYR_90=90 & DLEMO_90>=5) THEN ENROLL_90=3;
        ELSE ENROLL_90=4;
     END;
     ELSE IF HGC_90<0 & DIP_90=-3 THEN DO;
        HGC_90=-3;
        ENROLL_90=-3;
     END;
     IF HGC_90>20 THEN DO;
        HGC_90=-3;
        ENROLL_90=-3;
     END;
     IF HGC_90>HGC(89)+3 & HGC(89)>0 & DIP_90^=2 & DIP_90^=3 THEN DO;
        HGC_90=-3;
        ENROLL_90=-3;
     END;
     IF HGC_90>0 & HGC_90<HGC(89)-1 ! (HGC(89)=12 & HGC_90=11) THEN DO;
        HGC_90=-3;
        ENROLL_90=-3;
     END;
     IF (DIP(79)>1 ! DIP(80)>1 ! DIP(81)>1 ! DIP(82)>1 ! DIP(83)>1 ! 
         DIP(84)>1 ! DIP(85)>1 ! DIP(86)>1 ! DIP(87)>1 ! DIP(88)>1 ! 
         DIP(89)>1) & HGC_90<12 THEN DO;
        HGC_90 =12;
        IF ENROLL_90=1 ! ENROLL_90<0 THEN ENROLL_90=4;
     END;
     IF HGC_90=-3 & ENROLL_90=-4 THEN ENROLL_90=-3;
     ELSE IF HGC_90=-4 & ENROLL_90=-4 THEN DO;
        HGC_90=-3;
        ENROLL_90=-3;
     END;
 END;
 
 HGC_90=R(34015.)
 ENROLL_90=R(34016.)
 
 /*  EACH INSTANCE OF -3 FOR HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS      */
 /*  IS REVIEWED BY CHECKING SELECTED SCHOOL VARIABLES.  VALUES OF -3 ARE       */
 /*  RECODED TO VALID VALUES WHERE AUXILLIARY INFORMATION INDICATES.            */
 /*  HOWEVER, THERE ARE A NUMBER OF -3'S COMPUTED FOR HIGHEST GRADE             */
 /*  COMPLETED AND ENROLLMENT STATUS THAT REMAIN.                               */

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of May 1, 1991

/*  THE FOLLOWING SPSS CODE IS APPLIED TO THE DATA BEFORE THE PLI PROGRAM       */
/*  IS EXECUTED.  THE PURPOSE OF THE CODE IS TO APPROPRIATELY RECODE SELECTED   */
/*  1979 AND 1980 VARIABLES.                                                    */
/*                                                                              */
/*  DO IF (R2283 EQ 0 OR R2282 EQ 0)                                            */
/*  COMPUTE DLEMO79=R2287                                                       */
/*  COMPUTE DLEYR79=R2288                                                       */
/*  ELSE                                                                        */
/*  COMPUTE DLEMO79=R169                                                        */
/*  COMPUTE DLEYR79=R170                                                        */
/*  END IF                                                                      */
/*  DO IF (R4052 GT 0 AND R2283 NE 0 AND R2282 NE 0)                            */
/*  COMPUTE DLEMO80=R2287                                                       */
/*  COMPUTE DLEYR80=R2288                                                       */
/*  END IF                                                                      */
/*  DO IF (R2275 EQ 0 OR R2276 EQ 0)                                            */
/*  COMPUTE GRADE79=R2277                                                       */
/*  ELSE                                                                        */
/*  COMPUTE GRADE79=R2286                                                       */
/*  END IF                                                                      */
/*  DO IF (R2280 GE 0)                                                          */
/*  COMPUTE HGCS79=R2280                                                        */
/*  ELSE                                                                        */
/*  COMPUTE HGCS79=R173                                                         */
/*  END IF                                                                      */
/*  IF (R2276 EQ 0 AND R2286 GT 0) R156=1                                       */
/********************************************************************************/
 
 DCL 1 INREC7990,                                                            
 
     2 CURAT(79:90)  PIC '------9',
          /*  R(  156.) R( 2285.) R( 4168.) R( 6639.) R( 9053.) R(12052.)  */
          /*  R(16045.) R(19050.) R(23059.) R(25084.) R(29075.) R(31096.)  */
 
     2 DIP(79:90)    PIC '------9',
          /*  R(  183.) R( 2300.) R( 4182.) R( 6653.) R( 9067.) R(12066.)  */
          /*  R(16059.) R(19061.) R(23070.) R(25095.) R(29086.) R(31107.)  */
 
     2 DLEMO(79:90)  PIC '------9',
          /*  DLEMO79   DLEMO80   R( 4170.) R( 6641.) R( 9055.) R(12054.)  */
          /*  R(16047.) R(19052.) R(23061.) R(25086.) R(29077.) R(31098.)  */
 
     2 DLEYR(79:90)  PIC '------9',
          /*  DLEYR79   DLEYR80   R( 4171.) R( 6642.) R( 90546) R(12055.)  */
          /*  R(16048.) R(19053.) R(23062.) R(25087.) R(29078.) R(31099.)  */
 
     2 GRADE(79:90)  PIC '------9',
          /*  GRADE79   R( 2286.) R( 4169.) R( 6640.) R( 9054.) R(12053.)  */
          /*  R(16046.) R(19051.) R(23060.) R(25085.) R(29076.) R(31097.)  */
 
     2 HGA(79:90)    PIC '------9',
          /*  R(  172.) R( 2291.) R( 4173.) R( 6644.) R( 9058.) R(12057.)  */
          /*  R(16050.) R(19055.) R(23064.) R(25089.) R(29080.) R(31101.)  */
 
     2 HGC(79:90)    PIC '------9',
          /*  R( 2167.) R( 4064.) R( 6189.) R( 8982.) R(11450.) R(15202.)  */
          /*  R(18909.) R(22580.) R(24454.) R(28711.) R(30748.) R(34015.)  */
 
     2 HGCS(79:90)   PIC '------9',
          /*  HGCS79    R( 2292.) R( 4174.) R( 6645.) R( 9059.) R(12058.)  */
          /*  R(16051.) R(19056.) R(23065.) R(25090.) R(29081.) R(31102.)  */
 
     2 INTMO(79:90)  PIC '------9',
          /*  R( 1725.) R( 3292.) R( 5307.) R( 8099.) R(10457.) R(14275.)  */
          /*  R(17946.) R(21562.) R(23657.) R(27425.) R(29861.) R(33025.)  */
 
     2 WEIGHT(79:90) PIC '9999999';
          /*  R( 2161.) R( 4052.) R( 6146.) R( 8967.) R(11444.) R(15196.)  */
          /*  R(18902.) R(22573.) R(24445.) R(28700.) R(30738.) R(34002.)  */
 
 DCL 1 INREC91,
     2 WEIGHT_91    PIC '9999999',  /*  R(36558.)  */
     2 SCHOOL_91,
       5 ASLI_91    PIC '------9',  /*  R(35070.)  */
       5 CURAT_91   PIC '------9',  /*  R(35096.)  */
       5 DIP_91     PIC '------9',  /*  R(35107.)  */
       5 DLEMO_91   PIC '------9',  /*  R(35098.)  */
       5 DLEYR_91   PIC '------9',  /*  R(35099.)  */
       5 GRADE_91   PIC '------9',  /*  R(35097.)  */
       5 HGA_91     PIC '------9',  /*  R(35101.)  */
       5 HGCS_91    PIC '------9',  /*  R(35102.)  */
       5 INTMO_91   PIC '------9',  /*  R(35734.)  */
       5 HAVEDIP_91 PIC '------9',  /*  R(35106.)  */
       5 ATTCOL_91  PIC '------9';  /*  COMPUTE ATTCOL_91=0                */
                                    /*  IF R(35103.)>3 THEN ATTCOL_91=1    */
       5 GRA_91     PIC '------9',  /*  COMPUTE GRA_91=-3                  */
                                    /*  IF R(35096.)=1                     */
                                    /*  THEN GRA_91=R(35097.)              */
                                    /*  ELSE IF R(35096.)=0                */
                                    /*  THEN GRA_91=R(35101.)              */
                                    /*  ELSE IF R(35070.)=0                */
                                    /*  THEN GRA_91=-4                     */
 
  /*  CREATION OF HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS      */
  /*  AS OF 5-1-91                                                   */
 
    HGC_91=-4;
    ENROLL_91=-4;
    DO I=80 TO 90;
       IF WEIGHT(I)=0 THEN DO;
          HGCS(I)=-5;
          GRADE(I)=-5;
       END;    
    END;
    IF WEIGHT_91=0 THEN DO;
       HGCS_91=-5;
       GRADE_91=-5;
       ENROLL_91=-5;
       HGC_91=-5;
    END;
 
  IF WEIGHT_91>0 THEN DO;
    IF ASLI_91=0 & (HAVEDIP_91=-4 ! HAVEDIP_91=0) THEN DO;
       IF WEIGHT(90)>0 THEN DO;
           IF INTMO(90)>=5 & (CURAT(90)=1 ! (DLEMO(90)>=5 & DLEYR(90)=90)) &
              HGCS(90)>HGC(90) THEN HGC_91=HGCS(90);
           ELSE HGC_91=HGC(90);
        END;
       IF WEIGHT(89)>0 THEN DO;
           IF INTMO(89)>=5 & (CURAT(89)=1 ! (DLEMO(89)>=5 & DLEYR(89)=89)) &
              HGCS(89)>HGC(89) THEN HGC_91=HGCS(89);
           ELSE HGC_91=HGC(89);
        END;
        ELSE IF WEIGHT(88)>0 THEN DO;
           IF INTMO(88)>=5 & (CURAT(88)=1 ! (DLEMO(88)>=5 & DLEYR(88)=88)) &
              HGCS(88)>HGC(88) THEN HGC_91=HGCS(88);
           ELSE HGC_91=HGC(88);
        END;
        ELSE IF WEIGHT(87)>0 THEN DO;
           IF INTMO(87)>=5 & (CURAT(87)=1 ! (DLEMO(87)>=5 & DLEYR(87)=87)) &
              HGCS(87)>HGC(87) THEN HGC_91=HGCS(87);
           ELSE HGC_91=HGC(87);
        END;
        ELSE IF WEIGHT(86)>0 THEN DO;
           IF INTMO(86)>=5 & (CURAT(86)=1 ! (DLEMO(86)>=5 & DLEYR(86)=86)) &
              HGCS(86)>HGC(86) THEN HGC_91=HGCS(86);
           ELSE HGC_91=HGC(86);
        END;
        ELSE IF WEIGHT(85)>0 THEN DO;
           IF INTMO(85)>=5 & (CURAT(85)=1 ! (DLEMO(85)>=5 & DLEYR(85)=85)) &
              HGCS(85)>HGC(85) THEN HGC_91=HGCS(85);
           ELSE HGC_91=HGC(85);
        END;
        ELSE IF WEIGHT(84)>0 THEN DO;
           IF INTMO(84)>=5 & (CURAT(84)=1 ! (DLEMO(84)>=5 & DLEYR(84)=84)) &
              HGCS(84)>HGC(84) THEN HGC_91=HGCS(84);
           ELSE HGC_91=HGC(84);
        END;
        ELSE IF WEIGHT(83)>0 THEN DO;
           IF INTMO(83)>=5 & (CURAT(83)=1 ! (DLEMO(83)>=5 & DLEYR(83)=83)) &
              HGCS(83)>HGC(83) THEN HGC_91=HGCS(83);
           ELSE HGC_91=HGC(83);
        END;
        ELSE IF WEIGHT(82)>0 THEN DO;
           IF INTMO(82)>=5 & (CURAT(82)=1 ! (DLEMO(82)>=5 & DLEYR(82)=82)) &
              HGCS(82)>HGC(82) THEN HGC_91=HGCS(82);
           ELSE HGC_91=HGC(82);
        END;
        ELSE IF WEIGHT(81)>0 THEN DO;
           IF INTMO(81)>=5 & (CURAT(81)=1 ! (DLEMO(81)>=5 & DLEYR(81)=81)) &
              HGCS(81)>HGC(81) THEN HGC_91=HGCS(81);
           ELSE HGC_91=HGC(81);
        END;
        ELSE IF WEIGHT(80)>0 THEN DO;
           IF INTMO(80)>=5 & (CURAT(80)=1 ! (DLEMO(80)>=5 & DLEYR(80)=80)) &
              HGCS(80)>HGC(80) THEN HGC_91=HGCS(80);
           ELSE HGC_91=HGC(80);
        END;
        ELSE DO;
           IF INTMO(79)>=5 & (CURAT(79)=1 ! (DLEMO(79)>=5 & DLEYR(79)=79)) &
              HGCS(79)>HGC(79) THEN HGC_91=HGCS(79);
           ELSE HGC_91=HGC(79);
        END;
        IF HGC_91>=12 THEN ENROLL_91=4;
        ELSE IF HGC_91>=0 THEN ENROLL_90=1;
     END;
     ELSE IF ASLI_91=1 THEN DO;
        IF HGCS_91<=0 THEN DO;
           IF CURAT_91=1 & GRADE_91>=1 THEN DO;
              HGC_91=GRADE_91-1;
              IF HGC_91>=12 THEN ENROLL_91=3;
              ELSE ENROLL_91=2;
           END;
           ELSE IF CURAT_91=0 & HGA_91>=1 THEN DO;
              IF DLEYR_91<90 ! DLEMO_91<5 THEN DO;
                 HGC_91=HGA_91;
                 IF HGC_91>=12 THEN ENROLL_91=4;
                 ELSE ENROLL_91=1;
              END;
              ELSE DO;
                 HGC_91=HGA_91-1;
                 IF HGC_91>=12 THEN ENROLL_91=4;
                 ELSE ENROLL_91=1;
              END;
           END;
        END;
        ELSE DO;
           IF HGCS_91=HGA_91 ! HGCS_91=GRADE_91 THEN DO;
              IF (DLEYR_91=91 & DLEMO_91>=5) ! (INTMO_91>=5 &
                 CURAT_91=1) THEN DO;
                 HGC_91=HGCS_91-1;
                 IF HGC_91>=12 THEN ENROLL_91=3;
                 ELSE ENROLL_91=2;
              END;
              ELSE HGC_91=HGCS_91;
           END;
           IF HGCS_91=HGA_91-1 ! HGCS_91=GRADE_91-1 THEN
              HGC_91=HGCS_91;
           ELSE IF (HGCS_91<HGA_91 & HGA_91>0 & HGA_91<20) !
              (HGCS_91<GRADE_91 & GRADE_91>0 & GRADE_91<20) THEN
              HGC_91=HGCS_91;
           IF ENROLL_91=-4 & CURAT_91=1 & HGC_91>=0 THEN DO;
              IF HGC_91>=12 THEN ENROLL_91=3;
              ELSE ENROLL_91=2;
           END;
           IF ENROLL_91=-4 & CURAT_91=0 & HGC_91>=0 THEN DO;
              IF HGC_91>=12 THEN ENROLL_91=4;
              ELSE ENROLL_91=1;
           END;
        END;
     END;
     IF ((HGC_91=10 ! HGC_91=11) & (HAVEDIP_91=1 ! ATTCOL_91=1)) !
       (DIP_91=2 & HGC_91<12) ! (HGC_91=-4 & (DIP_91=1 ! DIP_91=3))
        THEN DO;
        HGC_91=12;
        IF ENROLL_91>0 THEN ENROLL_91=5-ENROLL_90;
        ELSE IF CURAT_91=1 ! (DLEYR_91=91 & DLEMO_91>=5) THEN ENROLL_91=3;
        ELSE ENROLL_91=4;
     END;
     ELSE IF HGC_91<0 & DIP_91=-3 THEN DO;
        HGC_91=-3;
        ENROLL_91=-3;
     END;
     IF HGC_91>20 THEN DO;
        HGC_91=-3;
        ENROLL_91=-3;
     END;
     IF HGC_91>HGC(90)+3 & HGC(90)>0 & DIP_91^=2 & DIP_91^=3 THEN DO;
        HGC_91=-3;
        ENROLL_91=-3;
     END;
     IF HGC_91>0 & HGC_91<HGC(90)-1 ! (HGC(90)=12 & HGC_91=11) THEN DO;
        HGC_91=-3;
        ENROLL_91=-3;
     END;
     IF (DIP(79)>1 ! DIP(80)>1 ! DIP(81)>1 ! DIP(82)>1 ! DIP(83)>1 ! 
         DIP(84)>1 ! DIP(85)>1 ! DIP(86)>1 ! DIP(87)>1 ! DIP(88)>1 ! 
         DIP(89)>1 ! DIP(90)>1) & HGC_91<12 THEN DO;
        HGC_91=12;
        IF ENROLL_91=1 ! ENROLL_91<0 THEN ENROLL_91=4;
     END;
     IF HGC_91=-3 & ENROLL_91=-4 THEN ENROLL_91=-3;
     ELSE IF HGC_91=-4 & ENROLL_91=-4 THEN DO;
        HGC_91=-3;
        ENROLL_91=-3;
     END;
 END;
 
 HGC_91=R(36569.)
 ENROLL_91=R(36570.)
 
 /*  EACH INSTANCE OF -3 FOR HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS      */
 /*  IS REVIEWED BY CHECKING SELECTED SCHOOL VARIABLES.  VALUES OF -3           */
 /*  ARE RECODED TO VALID VALUES WHERE AUXILLIARY INFORMATION INDICATES.        */
 /*  HOWEVER, THERE ARE A NUMBER OF -3'S COMPUTED FOR HIGHEST GRADE             */
 /*  COMPLETED AND ENROLLMENT STATUS THAT REMAIN.                               */

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of May 1, 1992

 /*  THE FOLLOWING CODE IS APPLIED TO THE DATA BEFORE THE PLI PROGRAM           */
 /*  IS EXECUTED.  THE PURPOSE OF THE CODE IS TO APPROPRIATELY RECODE SELECTED  */
 /*  1979 AND 1980 VARIABLES.                                                   */
 /*                                                                             */
 /* IF (R2283 EQ 0 OR R2282 EQ 0) THEN DO; DLEMO79=R2287; DLEYR79=R2288; END;   */
 /*  ELSE DO; DLEMO79=R169; DLEYR79=R170; END;                                  */
 /* IF (R4052 GT 0 AND R2283 NE 0 AND R2282 NE 0) THEN DO;                      */
 /*  DLEMO80=R2287; DLEYR80=R2288; END;                                         */
 /*  IF (R2275 EQ 0 OR R2276 EQ 0) THEN GRADE79=R2277 ;                         */
 /*  ELSE GRADE79=R2286;                                                        */
 /*  IF (R2280 GE 0) THEN HGCS79=R2280;                                         */
 /*  ELSE                                                                       */
 /*  COMPUTE HGCS79=R173                                                        */
 /*  END IF                                                                     */
 /*  IF (R2276 EQ 0 AND R2286 GT 0) R156=1                                      */
/********************************************************************************/
 
 DCL 1 INREC79OLD,
 
     2 CURAT(79:LASTYR)  PIC '------9',
          /*  R(  156.) R( 2285.) R( 4168.) R( 6639.) R( 9053.) R(12052.)  */
          /*  R(16045.) R(19050.) R(23059.) R(25084.) R(29075.) R(31096.)  */
          /*  R(35096.)  */
     2 DIP(79:LASTYR)    PIC '------9',
          /*  R(  183.) R( 2300.) R( 4182.) R( 6653.) R( 9067.) R(12066.)  */
          /*  R(16059.) R(19061.) R(23070.) R(25095.) R(29086.) R(31107.)  */
          /*  R(35107.)  */
     2 DLEMO(79:LASTYR)  PIC '------9',
          /*  DLEMO79   DLEMO80   R( 4170.) R( 6641.) R( 9055.) R(12054.)  */
          /*  R(16047.) R(19052.) R(23061.) R(25086.) R(29077.) R(31098.)  */
          /*  R(35098.)  */
     2 DLEYR(79:LASTYR)  PIC '------9',
          /*  DLEYR79   DLEYR80   R( 4171.) R( 6642.) R( 90546) R(12055.)  */
          /*  R(16048.) R(19053.) R(23062.) R(25087.) R(29078.) R(31099.)  */
          /*  R(35099.)  */
     2 GRADE(79:LASTYR)  PIC '------9',
          /*  GRADE79   R( 2286.) R( 4169.) R( 6640.) R( 9054.) R(12053.)  */
          /*  R(16046.) R(19051.) R(23060.) R(25085.) R(29076.) R(31097.)  */
          /*  R(35097.)  */
     2 HGA(79:LASTYR)    PIC '------9',
          /*  R(  172.) R( 2291.) R( 4173.) R( 6644.) R( 9058.) R(12057.)  */
          /*  R(16050.) R(19055.) R(23064.) R(25089.) R(29080.) R(31101.)  */
          /*  R(35101.)  */
     2 HGC(79:LASTYR)    PIC '------9',
          /*  R( 2167.) R( 4064.) R( 6189.) R( 8982.) R(11450.) R(15202.)  */
          /*  R(18909.) R(22580.) R(24454.) R(28711.) R(30748.) R(34015.)  */
          /*  R(36569.) */
     2 HGCS(79:LASTYR)   PIC '------9',
          /*  HGCS79    R( 2292.) R( 4174.) R( 6645.) R( 9059.) R(12058.)  */
          /*  R(16051.) R(19056.) R(23065.) R(25090.) R(29081.) R(31102.)  */
          /*  R(35102.)  */
     2 INTMO(79:LASTYR)  PIC '------9',
          /*  R( 1725.) R( 3292.) R( 5307.) R( 8099.) R(10457.) R(14275.)  */
          /*  R(17946.) R(21562.) R(23657.) R(27425.) R(29861.) R(33025.)  */
          /*  R(35734.)  */
     2 WEIGHT(79:LASTYR) PIC '9999999',
          /*  R( 2161.) R( 4052.) R( 6146.) R( 8967.) R(11444.) R(15196.)  */
          /*  R(18902.) R(22573.) R(24445.) R(28700.) R(30738.) R(34002.)  */
          /*  R(36558.)  */
     2 WEIGHT92    PIC '9999999';  /*  R(36558.)  */
 
 DCL 1 INRECNEW ,
     2 NORCID_CUR PIC '------9',
     2 INTOB_CUR     PIC '9999999',   /*  DUMMY  */
     2 SCHOOL_CUR,
       5 ASLI_CUR    PIC '------9',  /*  R(37070.)  */
       5 CURAT_CUR   PIC '------9',  /*  R(37096.)  */
       5 DIP_CUR     PIC '------9',  /*  R(37107.)  */
       5 DLEMO_CUR   PIC '------9',  /*  R(37098.)  */
       5 DLEYR_CUR   PIC '------9',  /*  R(37099.)  */
       5 GRA_CUR     PIC '------9', /*  COMPUTE GRA_CUR=-3                  */
                                    /*  IF R(37096.)=1                      */
                                    /*  THEN GRA_CUR=R(37096.)              */
                                    /*  ELSE IF R(37096.)=0                 */
                                    /*  THEN GRA_CUR=R(37100.)              */
                                    /*  ELSE IF R(37070.)=0                 */
                                    /*  THEN GRA_CUR=-4                     */
       5 GRADE_CUR   PIC '------9',  /*  R(37097.)  */
       5 HGA_CUR     PIC '------9',  /*  R(37101.)  */
       5 HGCS_CUR    PIC '------9',  /*  R(37102.)  */
       5 INTMO_CUR   PIC '------9',  /*  R(39176.)  */
       5 HAVEDIP_CUR PIC '------9',  /*  R(37106.)  */
       5 ATTCOL_CUR  PIC '------9';  /*  COMPUTE ATTCOL_CUR=0                */
                                    /*  IF R(37102.)>3 THEN ATTCOL_CUR=1     */
 
 /*  CREATE OF HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS
     AS OF 5-1-92 */
 
    HGC_CUR=-4;
    ENROLL_CUR=-4;
    DO I=80 TO LASTYR;
       IF WEIGHT(I)=0 THEN DO;
          HGCS(I)=-5;
          GRADE(I)=-5;
       END;    
    END;
  IF WEIGHT92 > 0 THEN DO;       
    IF ASLI_CUR=0 & (HAVEDIP_CUR=-4 | HAVEDIP_CUR=0) THEN DO;  /* ATT NO */
    DO I = LASTYR TO 79 BY -1 WHILE(HGC_CUR = -4);  /* SEARCH */
       IF WEIGHT(I) > 0 THEN DO;   /* SEARCH INT YES */ 
           IF INTMO(I)>=5 & (CURAT(I)=1 | (DLEMO(I)>=5 & DLEYR(I)=I)) &
              HGCS(I)>HGC(I) THEN HGC_CUR=HGCS(I);
           ELSE HGC_CUR=HGC(I);
        END;    /* SEARCH INT YES */ 
     END;   /* SEARCH */
        IF HGC_CUR>=12 THEN ENROLL_CUR=4;
        ELSE IF HGC_CUR>=0 THEN ENROLL_CUR=1;
   END; /* ATT NO */
     IF ASLI_CUR=1 THEN DO;     /*ASLI = YES */
        IF HGCS_CUR <=0 THEN DO;     /* HGC_CUR STILL -4 */
           IF CURAT_CUR=1 & GRADE_CUR>=1 THEN DO; /* CURAT AND GRADE */
              HGC_CUR=GRADE_CUR-1;
              IF HGC_CUR>=12 THEN ENROLL_CUR=3;
              ELSE ENROLL_CUR=2;
                                             END; /* CURAT AND GRADE */
           ELSE IF CURAT_CUR=0 & HGA_CUR>=1 THEN DO;  /* NOTCURAT BUT  GRADE */
              IF DLEYR_CUR<LASTYR | DLEMO_CUR<5 THEN DO;  /* DATES */
                 HGC_CUR=HGA_CUR;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=4;
                 ELSE ENROLL_CUR=1;
                                                 END;   /* DATES */
              ELSE DO;                    
                 HGC_CUR=HGA_CUR-1;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=4;
                 ELSE ENROLL_CUR=1;
              END;                                    /* DATES OK */
           END;                  /* NOTCURAT BUT  GRADE */   
        END;                         /* HGC_CUR STILL -4 */
        ELSE DO;               /*ENROLL  */
           IF HGCS_CUR=HGA_CUR | HGCS_CUR=GRADE_CUR THEN DO;
              IF (DLEYR_CUR=CURANTYR & DLEMO_CUR>=5) | (INTMO_CUR>=5 &
                 CURAT_CUR=1) THEN DO;
                 HGC_CUR=HGCS_CUR-1;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=3;
                 ELSE ENROLL_CUR=2;
                                 END;
              ELSE HGC_CUR=HGCS_CUR; 
                                                         END;
           IF HGCS_CUR=HGA_CUR-1 | HGCS_CUR=GRADE_CUR-1 THEN 
              HGC_CUR=HGCS_CUR;
           ELSE IF (HGCS_CUR<HGA_CUR & HGA_CUR>0 & HGA_CUR<20) |
              (HGCS_CUR<GRADE_CUR & GRADE_CUR>0 & GRADE_CUR<20) THEN 
              HGC_CUR=HGCS_CUR; 
           IF ENROLL_CUR=-4 & CURAT_CUR=1 & HGC_CUR>=0 THEN DO;
              IF HGC_CUR>=12 THEN ENROLL_CUR=3;
              ELSE ENROLL_CUR=2;
                                                            END;
           IF ENROLL_CUR=-4 & CURAT_CUR=0 & HGC_CUR>=0 THEN DO;
              IF HGC_CUR>=12 THEN ENROLL_CUR=4;
              ELSE ENROLL_CUR=1;
                                                            END;
          END;   
                                                     END; /* ASLI = YES */
     IF ((HGC_CUR=10 | HGC_CUR=11) & (HAVEDIP_CUR=1 | ATTCOL_CUR=1)) |
       (DIP_CUR=2 & HGC_CUR<12) | (HGC_CUR=-4 & (DIP_CUR=1 | DIP_CUR=3))
        THEN DO;
        HGC_CUR=12;
        IF ENROLL_CUR>0 THEN ENROLL_CUR=5-ENROLL_CUR;
        ELSE IF CURAT_CUR=1 | (DLEYR_CUR=LASTYR & DLEMO_CUR>=5)
        THEN ENROLL_CUR=3;
        ELSE ENROLL_CUR=4;
           END;          
     ELSE IF HGC_CUR<0 & DIP_CUR=-3 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
                                         END;
     IF HGC_CUR>20 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
                       END;
    IF HGC_CUR>HGC(LASTYR)+3 & HGC(LASTYR)>0 & DIP_CUR^=2 & DIP_CUR^=3 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
                                                                           END;
     IF HGC_CUR>0 & HGC_CUR<HGC(LASTYR)-1 | (HGC(LASTYR)=12 & HGC_CUR=11)
      THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
          END;   
       END; /*NEW */
        TRU= 0;
     DO I=79 TO LASTYR BY 1;
        IF DIP(I)>1 THEN TRU =1;END;
        IF TRU = 1 & HGC_CUR<12 THEN HGC_CUR=12;
        IF TRU = 1 & (ENROLL_CUR=1 | ENROLL_CUR<0) THEN ENROLL_CUR=4;
        IF HGC_CUR=-3 & ENROLL_CUR=-4 THEN ENROLL_CUR=-3;
     ELSE IF HGC_CUR=-4 & ENROLL_CUR=-4 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
     END;
 
  /*  EACH INSTANCE OF -3 FOR HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS     */
  /*  IS REVIEWED BY CHECKING SELECTED SCHOOL VARIABLES.  VALUES OF -3          */
  /*  ARE RECODED TO VALID VALUES WHERE AUXILLIARY INFORMATION INDICATES.       */
  /*  HOWEVER, THERE ARE A NUMBER OF -3S COMPUTED FOR HIGHEST GRADE             */
  /*  COMPLETED AND ENROLLMENT STATUS THAT REMAIN.                              */
 
 HGC_92=R(36569.)   
 ENROLL_92=R(36570.) 

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of May 1, 1993

 /*  THE FOLLOWING CODE IS APPLIED TO THE DATA BEFORE THE PLI PROGRAM          */
 /*  IS EXECUTED.  THE PURPOSE OF THE CODE IS TO APPROPRIATELY RECODE          */
 /*  SELECTED 1979 AND 1980 VARIABLES.                                         */
 /*                                                                            */
 /* IF (R2283 EQ 0 OR R2282 EQ 0) THEN DO; DLEMO79=R2287; DLEYR79=R2288; END;  */
 /*  ELSE DO; DLEMO79=R169; DLEYR79=R170; END;                                 */
 /* IF (R4052 GT 0 AND R2283 NE 0 AND R2282 NE 0) THEN DO;                     */
 /*  DLEMO80=R2287; DLEYR80=R2288; END;                                        */
 /*  IF (R2275 EQ 0 OR R2276 EQ 0) THEN GRADE79=R2277 ;                        */
 /*  ELSE GRADE79=R2286;                                                       */
 /*  IF (R2280 GE 0) THEN HGCS79=R2280;                                        */
 /*  ELSE                                                                      */
 /*  COMPUTE HGCS79=R173                                                       */
 /*  END IF                                                                    */
 /*  IF (R2276 EQ 0 AND R2286 GT 0) R156=1                                     */
 /******************************************************************************/
 
 DCL 1 INREC79OLD,
     2 NORCID_OLD PIC '------9',
     2 PUBID_OLD PIC '------9',
     2 CURAT(79:LASTYR)  PIC '------9',
          /*  R(  156.) R( 2285.) R( 4168.) R( 6639.) R( 9053.) R(12052.)  */
          /*  R(16045.) R(19050.) R(23059.) R(25084.) R(29075.) R(31096.)  */
          /*  R(35096.) R(37096.) */
     2 DIP(79:LASTYR)    PIC '------9',
          /*  R(  183.) R( 2300.) R( 4182.) R( 6653.) R( 9067.) R(12066.)  */
          /*  R(16059.) R(19061.) R(23070.) R(25095.) R(29086.) R(31107.)  */
          /*  R(35107.) R(37107.) */
     2 DLEMO(79:LASTYR)  PIC '------9',
          /*  DLEMO79   DLEMO80   R( 4170.) R( 6641.) R( 9055.) R(12054.)  */
          /*  R(16047.) R(19052.) R(23061.) R(25086.) R(29077.) R(31098.)  */
          /*  R(35098.) R(37098.) */
     2 DLEYR(79:LASTYR)  PIC '------9',
          /*  DLEYR79   DLEYR80   R( 4171.) R( 6642.) R( 90546) R(12055.)  */
          /*  R(16048.) R(19053.) R(23062.) R(25087.) R(29078.) R(31099.)  */
          /*  R(35099.) R(37099.) */
     2 GRADE(79:LASTYR)  PIC '------9',
          /*  GRADE79   R( 2286.) R( 4169.) R( 6640.) R( 9054.) R(12053.)  */
          /*  R(16046.) R(19051.) R(23060.) R(25085.) R(29076.) R(31097.)  */
          /*  R(35097.) R(37097.) */
     2 HGA(79:LASTYR)    PIC '------9',
          /*  R(  172.) R( 2291.) R( 4173.) R( 6644.) R( 9058.) R(12057.)  */
          /*  R(16050.) R(19055.) R(23064.) R(25089.) R(29080.) R(31101.)  */
          /*  R(35101.) R(37101.) */
     2 HGC(79:LASTYR)    PIC '------9',
          /*  R( 2167.) R( 4064.) R( 6189.) R( 8982.) R(11450.) R(15202.)  */
          /*  R(18909.) R(22580.) R(24454.) R(28711.) R(30748.) R(34015.)  */
          /*  R(36569.) R(40074.)*/
     2 HGCS(79:LASTYR)   PIC '------9',
          /*  HGCS79    R( 2292.) R( 4174.) R( 6645.) R( 9059.) R(12058.)  */
          /*  R(16051.) R(19056.) R(23065.) R(25090.) R(29081.) R(31102.)  */
          /*  R(35102.) R(37102.) */
     2 INTMO(79:LASTYR)  PIC '------9',
          /*  R( 1725.) R( 3292.) R( 5307.) R( 8099.) R(10457.) R(14275.)  */
          /*  R(17946.) R(21562.) R(23657.) R(27425.) R(29861.) R(33025.)  */
          /*  R(35734.) R(39176.) */
     2 WEIGHT(79:LASTYR) PIC '9999999';
          /*  R( 2161.) R( 4052.) R( 6146.) R( 8967.) R(11444.) R(15196.)  */
          /*  R(18902.) R(22573.) R(24445.) R(28700.) R(30738.) R(34002.)  */
          /*  R(36558.) R(40063.) */
 
 DCL 1 INRECNEW,
     2 NORCID_CUR PIC '------9',
     2 INTOB_CUR     PIC '9999999',   /*  DUMMY  */
     2 SCHOOL_CUR,
       5 ASLI_CUR    PIC '------9',  /*  R(41347.)  */
       5 CURAT_CUR   PIC '------9',  /*  R(41374.)  */
       5 DIP_CUR     PIC '------9',  /*  R(41385.)  */
       5 DLEMO_CUR   PIC '------9',  /*  R(41376.)  */
       5 DLEYR_CUR   PIC '------9',  /*  R(41376.01.)  */
       5 GRA_CUR     PIC '------9', /*  COMPUTE GRA_CUR=-3                  */
                                    /*  IF R(41374.)=1                      */
                                    /*  THEN GRA_CUR=R(41374.)              */
                                    /*  ELSE IF R(41374.)=0                 */
                                    /*  THEN GRA_CUR=R(41378.)              */
                                    /*  ELSE IF R(41347.)=0                 */
                                    /*  THEN GRA_CUR=-4                     */
       5 GRADE_CUR   PIC '------9',  /*  R(41375.)  */
       5 HGA_CUR     PIC '------9',  /*  R(41378.)  */
       5 HGCS_CUR    PIC '------9',  /*  R(41379.)  */
       5 INTMO_CUR   PIC '------9',  /*  R(41002.)  */
       5 HAVEDIP_CUR PIC '------9',  /*  R(41384.)  */
       5 ATTCOL_CUR  PIC '------9';  /*  COMPUTE ATTCOL_CUR=0                */
                                    /*  IF R(41379.)>3 THEN ATTCOL_CUR=1     */
 
 /*  CREATE OF HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS
     AS OF 5-1-93 */
 
    HGC_CUR=-4;
    ENROLL_CUR=-4;
    DO I=80 TO LASTYR;
       IF WEIGHT(I)=0 THEN DO;
          HGCS(I)=-5;
          GRADE(I)=-5;
       END;    
    END;
   /*IN 93 OLD AND NEW FILES HAVE ONLY INTERVIEWS */
   /* IF THERE IS A NEED TO UNCOMMENT LOOP BELOW  */
   /* IF RNICUR=-4 THEN DO;        -  LOOP NEW */
    IF ASLI_CUR=0 & (HAVEDIP_CUR=-4 | HAVEDIP_CUR=0) THEN DO;  /* ATT NO */
    DO I = LASTYR TO 79 BY -1 WHILE(HGC_CUR = -4);  /* SEARCH */
       IF WEIGHT(I) > 0 THEN DO;   /* SEA INT YES */ 
           IF INTMO(I)>=5 & (CURAT(I)=1 | (DLEMO(I)>=5 & DLEYR(I)=I)) &
              HGCS(I)>HGC(I) THEN HGC_CUR=HGCS(I);
           ELSE HGC_CUR=HGC(I);
        END;    /* SEA INT YES */ 
     END;   /* SEARCH */
        IF HGC_CUR>=12 THEN ENROLL_CUR=4;
        ELSE IF HGC_CUR>=0 THEN ENROLL_CUR=1;
   END; /* - ATT NO */
     IF ASLI_CUR=1 THEN DO;     /*ASLI = YES */
        IF HGCS_CUR <=0 THEN DO;     /* HGC_CUR STILL -4 */
           IF CURAT_CUR=1 & GRADE_CUR>=1 THEN DO; /* CURAT AND GRADE */
              HGC_CUR=GRADE_CUR-1;
              IF HGC_CUR>=12 THEN ENROLL_CUR=3;
              ELSE ENROLL_CUR=2;
                                             END; /* CURAT AND GRADE */
           ELSE IF CURAT_CUR=0 & HGA_CUR>=1 THEN DO;  /* NOTCURAT BUT  GRADE */
              IF DLEYR_CUR<LASTYR | DLEMO_CUR<5 THEN DO;  /* DATES */
                 HGC_CUR=HGA_CUR;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=4;
                 ELSE ENROLL_CUR=1;
                                                 END;   /* DATES */
              ELSE DO;                    
                 HGC_CUR=HGA_CUR-1;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=4;
                 ELSE ENROLL_CUR=1;
              END;                                    /* DATES OK */
           END;                  /* NOTCURAT BUT  GRADE */   
        END;                         /* HGC_CUR STILL -4 */
        ELSE DO;               /*ENROLL  */
           IF HGCS_CUR=HGA_CUR | HGCS_CUR=GRADE_CUR THEN DO;
              IF (DLEYR_CUR=CURANTYR & DLEMO_CUR>=5) | (INTMO_CUR>=5 &
                 CURAT_CUR=1) THEN DO;
                 HGC_CUR=HGCS_CUR-1;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=3;
                 ELSE ENROLL_CUR=2;
                                 END;
              ELSE HGC_CUR=HGCS_CUR; 
                                                         END;
           IF HGCS_CUR=HGA_CUR-1 | HGCS_CUR=GRADE_CUR-1 THEN 
              HGC_CUR=HGCS_CUR;
           ELSE IF (HGCS_CUR<HGA_CUR & HGA_CUR>0 & HGA_CUR<20) |
              (HGCS_CUR<GRADE_CUR & GRADE_CUR>0 & GRADE_CUR<20) THEN 
              HGC_CUR=HGCS_CUR; 
           IF ENROLL_CUR=-4 & CURAT_CUR=1 & HGC_CUR>=0 THEN DO;
              IF HGC_CUR>=12 THEN ENROLL_CUR=3;
              ELSE ENROLL_CUR=2;
                                                            END;
           IF ENROLL_CUR=-4 & CURAT_CUR=0 & HGC_CUR>=0 THEN DO;
              IF HGC_CUR>=12 THEN ENROLL_CUR=4;
              ELSE ENROLL_CUR=1;
                                                            END;
          END;   
                                                     END; /* ASLI = YES */
     IF ((HGC_CUR=10 | HGC_CUR=11) & (HAVEDIP_CUR=1 | ATTCOL_CUR=1)) |
       (DIP_CUR=2 & HGC_CUR<12) | (HGC_CUR=-4 & (DIP_CUR=1 | DIP_CUR=3))
        THEN DO;
        HGC_CUR=12;
        IF ENROLL_CUR>0 THEN ENROLL_CUR=5-ENROLL_CUR;
        ELSE IF CURAT_CUR=1 | (DLEYR_CUR=LASTYR & DLEMO_CUR>=5)
        THEN ENROLL_CUR=3;
        ELSE ENROLL_CUR=4;
           END;          
     ELSE IF HGC_CUR<0 & DIP_CUR=-3 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
                                         END;
     IF HGC_CUR>20 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
                       END;
    IF HGC_CUR>HGC(LASTYR)+3 & HGC(LASTYR)>0 & DIP_CUR^=2 & DIP_CUR^=3 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
                                                                           END;
     IF HGC_CUR>0 & HGC_CUR<HGC(LASTYR)-1 | (HGC(LASTYR)=12 & HGC_CUR=11)
      THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
          END;   
       /* END; LOOP NEW IN 93 OLD AND NEW FILES HAVE ONLY INTERVIEWS */
                /*      IF THERE IS A NEED TO UNCOMMENT THIS END     */
        TRU= 0;
     DO I=79 TO LASTYR BY 1;
        IF DIP(I)>1 THEN TRU =1;END;
        IF TRU = 1 & HGC_CUR<12 THEN HGC_CUR=12;
        IF TRU = 1 & (ENROLL_CUR=1 | ENROLL_CUR<0) THEN ENROLL_CUR=4;
        IF HGC_CUR=-3 & ENROLL_CUR=-4 THEN ENROLL_CUR=-3;
     ELSE IF HGC_CUR=-4 & ENROLL_CUR=-4 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
     END;
 
  /*  EACH INSTANCE OF -3 FOR HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS     */
  /*  IS REVIEWED BY CHECKING SELECTED SCHOOL VARIABLES.  VALUES OF -3          */
  /*  ARE RECODED TO VALID VALUES WHERE AUXILLIARY INFORMATION INDICATES.       */
  /*  HOWEVER, THERE ARE A NUMBER OF -3S COMPUTED FOR HIGHEST GRADE             */
  /*  COMPLETED AND ENROLLMENT STATUS THAT REMAIN.                              */
 
  /* HGC_93=R(44185.)    */
  /* ENROLL_93=R(44186.) */

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of May 1, 1994

 /*  THE FOLLOWING CODE IS APPLIED TO THE DATA BEFORE THE PLI PROGRAM           */
 /*  IS EXECUTED.  THE PURPOSE OF THE CODE IS TO APPROPRIATELY RECODE           */
 /*  SELECTED 1979 AND 1980 VARIABLES.                                          */
 /*                                                                             */
 /* IF (R2283 EQ 0 OR R2282 EQ 0) THEN DO; DLEMO79=R2287; DLEYR79=R2288;END;    */
 /*  ELSE DO; DLEMO79=R169; DLEYR79=R170; END;                                  */
 /* IF (R4052 GT 0 AND R2283 NE 0 AND R2282 NE 0) THEN DO;                      */
 /*  DLEMO80=R2287; DLEYR80=R2288; END;                                         */
 /*  IF (R2275 EQ 0 OR R2276 EQ 0) THEN GRADE79=R2277 ;                         */
 /*  ELSE GRADE79=R2286;                                                        */
 /*  IF (R2280 GE 0) THEN HGCS79=R2280;                                         */
 /*  ELSE                                                                       */
 /*  COMPUTE HGCS79=R173                                                        */
 /*  END IF                                                                     */
 /*  IF (R2276 EQ 0 AND R2286 GT 0) R156=1                                      */
 /*******************************************************************************/
 
 DCL 1 OUTREC,
     2 PUBID PIC '------9',
     2 NORCID PIC '------9',
     2 HGC_CUR PIC '------9',
     2 ENROLL_CUR PIC '------9';
    /*  2 CASEIDD CHAR(9), */
 DCL 1 INREC79OLD,
     2 NORCID_OLD PIC '------9',
     2 PUBID_OLD PIC '------9',
     2 CURAT(79:LASTYR)  PIC '------9',
          /*  R(  156.) R( 2285.) R( 4168.) R( 6639.) R( 9053.) R(12052.)  */
          /*  R(16045.) R(19050.) R(23059.) R(25084.) R(29075.) R(31096.)  */
          /*  R(35096.) R(37096.) R(41374.) */
     2 DIP(79:LASTYR)    PIC '------9',
          /*  R(  183.) R( 2300.) R( 4182.) R( 6653.) R( 9067.) R(12066.)  */
          /*  R(16059.) R(19061.) R(23070.) R(25095.) R(29086.) R(31107.)  */
          /*  R(35107.) R(37107.) R(41384.)*/
     2 DLEMO(79:LASTYR)  PIC '------9',
          /*  DLEMO79   DLEMO80   R( 4170.) R( 6641.) R( 9055.) R(12054.)  */
          /*  R(16047.) R(19052.) R(23061.) R(25086.) R(29077.) R(31098.)  */
          /*  R(35098.) R(37098.) R(41376.)*/
     2 DLEYR(79:LASTYR)  PIC '------9',
          /*  DLEYR79   DLEYR80   R( 4171.) R( 6642.) R( 90546) R(12055.)  */
          /*  R(16048.) R(19053.) R(23062.) R(25087.) R(29078.) R(31099.)  */
          /*  R(35099.) R(37099.) R(41376.01.)*/
     2 GRADE(79:LASTYR)  PIC '------9',
          /*  GRADE79   R( 2286.) R( 4169.) R( 6640.) R( 9054.) R(12053.)  */
          /*  R(16046.) R(19051.) R(23060.) R(25085.) R(29076.) R(31097.)  */
          /*  R(35097.) R(37097.) R(41375.)*/
     2 HGA(79:LASTYR)    PIC '------9',
          /*  R(  172.) R( 2291.) R( 4173.) R( 6644.) R( 9058.) R(12057.)  */
          /*  R(16050.) R(19055.) R(23064.) R(25089.) R(29080.) R(31101.)  */
          /*  R(35101.) R(37101.) R(41378.)*/
     2 HGC(79:LASTYR)    PIC '------9',
          /*  R( 2167.) R( 4064.) R( 6189.) R( 8982.) R(11450.) R(15202.)  */
          /*  R(18909.) R(22580.) R(24454.) R(28711.) R(30748.) R(34015.)  */
          /*  R(36569.) R(40074.) R(44185.)*/
     2 HGCS(79:LASTYR)   PIC '------9',
          /*  HGCS79    R( 2292.) R( 4174.) R( 6645.) R( 9059.) R(12058.)  */
          /*  R(16051.) R(19056.) R(23065.) R(25090.) R(29081.) R(31102.)  */
          /*  R(35102.) R(37102.) (R41379.)*/
     2 INTMO(79:LASTYR)  PIC '------9',
          /*  R( 1725.) R( 3292.) R( 5307.) R( 8099.) R(10457.) R(14275.)  */
          /*  R(17946.) R(21562.) R(23657.) R(27425.) R(29861.) R(33025.)  */
          /*  R(35734.) R(39176.) R(41002.)*/
     2 WEIGHT(79:LASTYR) PIC '9999999';
          /*  R( 2161.) R( 4052.) R( 6146.) R( 8967.) R(11444.) R(15196.)  */
          /*  R(18902.) R(22573.) R(24445.) R(28700.) R(30738.) R(34002.)  */
          /*  R(36558.) R(40063.) R(44174.)*/
 
   /*   2 CASEID CHAR(9), */
   /*   2 RNICUR    PIC '9999999';  - R(50805.)  */
 
 DCL 1 INRECNEW,
     2 NORCID_CUR PIC '------9',
     2 INTOB_CUR     PIC '9999999',   /*  DUMMY  */
     2 SCHOOL_CUR,
       5 ASLI_CUR    PIC '------9',  /*  R(45233.)  */
       5 CURAT_CUR   PIC '------9',  /*  R(45260.)  */
       5 DIP_CUR     PIC '------9',  /*  R(45271.)  */
       5 DLEMO_CUR   PIC '------9',  /*  R(45262.)  */
       5 DLEYR_CUR   PIC '------9',  /*  R(45262.01)  */
       5 GRA_CUR     PIC '------9', /*  COMPUTE GRA_CUR=-3                  */
                                    /*  IF R(45260.)=1                      */
                                    /*  THEN GRA_CUR=R(45260.)              */
                                    /*  ELSE IF R(45260.)=0                 */
                                    /*  THEN GRA_CUR=R(45264.)              */
                                    /*  ELSE IF R(45265.)=0                 */
                                    /*  THEN GRA_CUR=-4                     */
       5 GRADE_CUR   PIC '------9',  /*  R(45261.)  */
       5 HGA_CUR     PIC '------9',  /*  R(45264.)  */
       5 HGCS_CUR    PIC '------9',  /*  R(45265.)  */
       5 INTMO_CUR   PIC '------9',  /*  R(45002.)  */
       5 HAVEDIP_CUR PIC '------9',  /*  R(45270.)  */
       5 ATTCOL_CUR  PIC '------9';  /*  COMPUTE ATTCOL_CUR=0               */
                                    /*  IF R(45267.)>3 OR R(45268.)>3 OR    */
                                    /*     R(45278.)=1 THEN ATTCOL_CUR=1    */
  READOLD: READ FILE(INTOLD) INTO(INREC79OLD);
   erflg=0;
          KOUNT79OLD = KOUNT79OLD + 1;
  /*   PUBID=SUBSTR(CASEID,5,5); */
  /* CASEIDD=CASEID; */
  PUBID=PUBID_OLD;
  NORCID=NORCID_OLD;
 /*     IF RNICUR ^= -4 THEN DO; */
 /*       ENROLL_CUR=-5; */
 /*       HGC_CUR=-5; */
 /*       GO TO RECWRITE; END; */
 /*      ELSE IF RNICUR = -4 THEN DO;      - INT GET REC */
  READNEW: READ FILE(INNEW) INTO(INRECNEW);
          KOUNTNEW = KOUNTNEW + 1;
     IF NORCID_OLD^=NORCID_CUR THEN DO;   /* NO MATCH */
    PUT SKIP EDIT ('ERROR - NORCIDOLD=',NORCID_OLD,'NORCID_CUR=',NORCID_CUR)
                  (A,F(7),A,F(7));
    GO TO DONE;
                                   END;  /* NO MATCH */
  /*                                  END;  - INT NO MATCH */ 
 
 /*  CREATE OF HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS
     AS OF 5-1-94 */
    HGC_CUR=-4;
    ENROLL_CUR=-4;
    DO I=80 TO LASTYR;
       IF WEIGHT(I)=0 THEN DO;
          HGCS(I)=-5;
          GRADE(I)=-5;
       END;    
    END;
   /*IN 94 OLD AND NEW FILES HAVE ONLY INTERVIEWS */
   /* IF THERE IS A NEED TO UNCOMMENT LOOP BELOW  */
  /* IF RNICUR=-4 THEN DO;        -  LOOP NEW */
    IF ASLI_CUR=0 & (HAVEDIP_CUR=-4 | HAVEDIP_CUR=0) THEN DO;  /* ATT NO */
    DO I = LASTYR TO 79 BY -1 WHILE(HGC_CUR = -4);  /* SEARCH */
       IF WEIGHT(I) > 0 THEN DO;   /* SEA INT YES */ 
           IF INTMO(I)>=5 & (CURAT(I)=1 | (DLEMO(I)>=5 & DLEYR(I)=I)) &
              HGCS(I)>HGC(I) THEN HGC_CUR=HGCS(I);
           ELSE HGC_CUR=HGC(I);
        END;    /* SEA INT YES */ 
     END;   /* SEARCH */
        IF HGC_CUR>=12 THEN ENROLL_CUR=4;
        ELSE IF HGC_CUR>=0 THEN ENROLL_CUR=1;
   END; /* - ATT NO */
     IF ASLI_CUR=1 THEN DO;     /*ASLI = YES */
        IF HGCS_CUR <=0 THEN DO;     /* HGC_CUR STILL -4 */
           IF CURAT_CUR=1 & GRADE_CUR>=1 THEN DO; /* CURAT AND GRADE */
              HGC_CUR=GRADE_CUR-1;
              IF HGC_CUR>=12 THEN ENROLL_CUR=3;
              ELSE ENROLL_CUR=2;
                                             END; /* CURAT AND GRADE */
           ELSE IF CURAT_CUR=0 & HGA_CUR>=1 THEN DO;  /* NOTCURAT BUT GRADE */
              IF DLEYR_CUR<LASTYR | DLEMO_CUR<5 THEN DO;  /* DATES */
                 HGC_CUR=HGA_CUR;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=4;
                 ELSE ENROLL_CUR=1;
                                                 END;   /* DATES */
              ELSE DO;                    
                 HGC_CUR=HGA_CUR-1;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=4;
                 ELSE ENROLL_CUR=1;
              END;                                    /* DATES OK */
           END;                  /* NOTCURAT BUT  GRADE */   
        END;                         /* HGC_CUR STILL -4 */
        ELSE DO;               /*ENROLL  */
           IF HGCS_CUR=HGA_CUR | HGCS_CUR=GRADE_CUR THEN DO;
              IF (DLEYR_CUR=CURANTYR & DLEMO_CUR>=5) | (INTMO_CUR>=5 &
                 CURAT_CUR=1) THEN DO;
                 HGC_CUR=HGCS_CUR-1;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=3;
                 ELSE ENROLL_CUR=2;
                                 END;
              ELSE HGC_CUR=HGCS_CUR; 
                                                         END;
           IF HGCS_CUR=HGA_CUR-1 | HGCS_CUR=GRADE_CUR-1 THEN 
              HGC_CUR=HGCS_CUR;
           ELSE IF (HGCS_CUR<HGA_CUR & HGA_CUR>0 & HGA_CUR<20) |
              (HGCS_CUR<GRADE_CUR & GRADE_CUR>0 & GRADE_CUR<20) THEN 
              HGC_CUR=HGCS_CUR; 
           IF ENROLL_CUR=-4 & CURAT_CUR=1 & HGC_CUR>=0 THEN DO;
              IF HGC_CUR>=12 THEN ENROLL_CUR=3;
              ELSE ENROLL_CUR=2;
                                                            END;
           IF ENROLL_CUR=-4 & CURAT_CUR=0 & HGC_CUR>=0 THEN DO;
              IF HGC_CUR>=12 THEN ENROLL_CUR=4;
              ELSE ENROLL_CUR=1;
                                                            END;
          END;   
                                                     END; /* ASLI = YES */
     IF ((HGC_CUR=10 | HGC_CUR=11) & (HAVEDIP_CUR=1 | ATTCOL_CUR=1)) |
       (DIP_CUR=2 & HGC_CUR<12) | (HGC_CUR=-4 & (DIP_CUR=1 | DIP_CUR=3))
        THEN DO;
        HGC_CUR=12;
        IF ENROLL_CUR>0 THEN ENROLL_CUR=5-ENROLL_CUR;
        ELSE IF CURAT_CUR=1 | (DLEYR_CUR=LASTYR & DLEMO_CUR>=5)
        THEN ENROLL_CUR=3;
        ELSE ENROLL_CUR=4;
           END;          
     ELSE IF HGC_CUR<0 & DIP_CUR=-3 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
                                         END;
     IF HGC_CUR>20 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
                       END;
    IF HGC_CUR>HGC(LASTYR)+3 & HGC(LASTYR)>0 & DIP_CUR^=2 & DIP_CUR^=3 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
                                                                           END;
     IF HGC_CUR>0 & HGC_CUR<HGC(LASTYR)-1 | (HGC(LASTYR)=12 & HGC_CUR=11)
      THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
          END;   
       /* END; LOOP NEW IN 94 OLD AND NEW FILES HAVE ONLY INTERVIEWS */
                /*      IF THERE IS A NEED TO UNCOMMENT THIS END     */
        TRU= 0;
     DO I=79 TO LASTYR BY 1;
        IF DIP(I)>1 THEN TRU =1;END;
        IF TRU = 1 & HGC_CUR<12 THEN HGC_CUR=12;
        IF TRU = 1 & (ENROLL_CUR=1 | ENROLL_CUR<0) THEN ENROLL_CUR=4;
        IF HGC_CUR=-3 & ENROLL_CUR=-4 THEN ENROLL_CUR=-3;
     ELSE IF HGC_CUR=-4 & ENROLL_CUR=-4 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
     END;
 
  /*  EACH INSTANCE OF -3 FOR HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS     */
  /*  IS REVIEWED BY CHECKING SELECTED SCHOOL VARIABLES.  VALUES OF -3          */
  /*  ARE RECODED TO VALID VALUES WHERE AUXILLIARY INFORMATION INDICATES.       */
  /*  HOWEVER, THERE ARE A NUMBER OF -3S COMPUTED FOR HIGHEST GRADE             */
  /*  COMPLETED AND ENROLLMENT STATUS THAT REMAIN.                              */
 
  /* HGC_94=R(50815.)    */
  /* ENROLL_94=R(50816.) */

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of May 1, 1996

/*  CREATE OF HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS
     AS OF 5-1-96 */
 
  HGC_CUR=-4;
   ENROLL_CUR=-4;
   DO I=2 TO LASTRND;
       IF WEIGHT(I)=0 THEN DO;
          HGCS(I)=-5;
          GRADE(I)=-5;
       END;    
    END;
   /*IN 96 OLD AND NEW FILES HAVE ONLY INTERVIEWS */
   /* IF THERE IS A NEED TO UNCOMMENT LOOP BELOW  */
   /* IF RNICUR=-4 THEN DO;        -  LOOP NEW */
    IF ASLI_CUR=0 & (HAVEDIP_CUR=-4 | HAVEDIP_CUR=0) THEN DO;  /* ATT NO */
    DO I = LASTRND TO 1 BY -1 WHILE(HGC_CUR = -4);  /* SEARCH */
       IF WEIGHT(I) > 0 THEN DO;   /* SEA INT YES */ 
           IF INTMO(I)>=5 & (CURAT(I)=1 | (DLEMO(I)>=5 & DLEYR(I)=INTYR(I))) &
              HGCS(I)>HGC(I) THEN HGC_CUR=HGCS(I);
           ELSE HGC_CUR=HGC(I);
        END;    /* SEA INT YES */ 
     END;   /* SEARCH */
        IF HGC_CUR>=12 THEN ENROLL_CUR=4;
        ELSE IF HGC_CUR>=0 THEN ENROLL_CUR=1;
   END; /* - ATT NO */
     IF ASLI_CUR=1 THEN DO;     /*ASLI = YES */
        IF HGCS_CUR <=0 THEN DO;     /* HGC_CUR STILL -4 */
           IF CURAT_CUR=1 & GRADE_CUR>=1 THEN DO; /* CURAT AND GRADE */
              HGC_CUR=GRADE_CUR-1;
              IF HGC_CUR>=12 THEN ENROLL_CUR=3;
              ELSE ENROLL_CUR=2;
 
                                             END; /* CURAT AND GRADE */
           ELSE IF CURAT_CUR=0 & HGA_CUR>=1 THEN DO;  /* NOTCURAT BUT  GRADE */
              IF DLEYR_CUR<LASTYR | DLEMO_CUR<5 THEN DO;  /* DATES */
                 HGC_CUR=HGA_CUR;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=4;
                 ELSE ENROLL_CUR=1;
                                                 END;   /* DATES */
              ELSE DO;                    
                 HGC_CUR=HGA_CUR-1;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=4;
                 ELSE ENROLL_CUR=1;
              END;                                    /* DATES OK */
           END;                  /* NOTCURAT BUT  GRADE */   
        END;                         /* HGC_CUR STILL -4 */
        ELSE DO;               /*ENROLL  */
           IF HGCS_CUR=HGA_CUR | HGCS_CUR=GRADE_CUR THEN DO;
              IF (DLEYR_CUR=CURANTYR & DLEMO_CUR>=5) | (INTMO_CUR>=5 &
                 CURAT_CUR=1) THEN DO;
                 HGC_CUR=HGCS_CUR-1;
                 IF HGC_CUR>=12 THEN ENROLL_CUR=3;
                 ELSE ENROLL_CUR=2;
                                 END;
              ELSE HGC_CUR=HGCS_CUR; 
                                                         END;
           IF HGCS_CUR=HGA_CUR-1 | HGCS_CUR=GRADE_CUR-1 THEN 
              HGC_CUR=HGCS_CUR;
           ELSE IF (HGCS_CUR<HGA_CUR & HGA_CUR>0 & HGA_CUR<20) |
              (HGCS_CUR<GRADE_CUR & GRADE_CUR>0 & GRADE_CUR<20) THEN 
              HGC_CUR=HGCS_CUR; 
           IF ENROLL_CUR=-4 & CURAT_CUR=1 & HGC_CUR>=0 THEN DO;
              IF HGC_CUR>=12 THEN ENROLL_CUR=3;
              ELSE ENROLL_CUR=2;
                                                            END;
           IF ENROLL_CUR=-4 & CURAT_CUR=0 & HGC_CUR>=0 THEN DO;
              IF HGC_CUR>=12 THEN ENROLL_CUR=4;
              ELSE ENROLL_CUR=1;
                                                            END;
          END;   
                                                     END; /* ASLI = YES */
     IF ((HGC_CUR=10 | HGC_CUR=11) & (HAVEDIP_CUR=1 | ATTCOL_CUR=1)) |
       (DIP_CUR=2 & HGC_CUR<12) | (HGC_CUR=-4 & (DIP_CUR=1 | DIP_CUR=3))
        THEN DO;
        HGC_CUR=12;
        IF ENROLL_CUR>0 THEN ENROLL_CUR=5-ENROLL_CUR;
        ELSE IF CURAT_CUR=1 | (DLEYR_CUR=LASTYR & DLEMO_CUR>=5)
        THEN ENROLL_CUR=3;
        ELSE ENROLL_CUR=4;
           END;          
     ELSE IF HGC_CUR<0 & DIP_CUR=-3 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
         END;
     IF HGC_CUR>20 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
        END;
    IF HGC_CUR>HGC(LASTRND)+3 & HGC(LASTRND)>0 & DIP_CUR^=2 & DIP_CUR^=3 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
         END;
     IF HGC_CUR>0 & HGC_CUR<HGC(LASTRND)-1 | (HGC(LASTRND)=12 & HGC_CUR=11)
      THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
          END;   
       /* END; LOOP NEW IN 96 OLD AND NEW FILES HAVE ONLY INTERVIEWS */
                /*      IF THERE IS A NEED TO UNCOMMENT THIS END     */
        TRU= 0;
     DO I=1 TO LASTRND BY 1;
        IF DIP(I)>1 THEN TRU =1;END;
        IF TRU = 1 & HGC_CUR<12 THEN HGC_CUR=12;
        IF TRU = 1 & (ENROLL_CUR=1 | ENROLL_CUR<0) THEN ENROLL_CUR=4;
        IF HGC_CUR=-3 & ENROLL_CUR=-4 THEN ENROLL_CUR=-3;
     ELSE IF HGC_CUR=-4 & ENROLL_CUR=-4 THEN DO;
        HGC_CUR=-3;
        ENROLL_CUR=-3;
     END;
 
  /*  EACH INSTANCE OF -3 FOR HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS     */
  /*  IS REVIEWED BY CHECKING SELECTED SCHOOL VARIABLES.  VALUES OF -3          */
  /*  ARE RECODED TO VALID VALUES WHERE AUXILLIARY INFORMATION INDICATES.       */
  /*  HOWEVER, THERE ARE A NUMBER OF -3S COMPUTED FOR HIGHEST GRADE             */
  /*  COMPLETED AND ENROLLMENT STATUS THAT REMAIN.                              */
 
  /* HGC_96=R(51668.)    */
  /* ENROLL_96=R(51669.) */

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of MAY 1, 1998

NOTE: The PL/1 code used to create Highest Grade Completed and Enrollment Status variables through the 1996 release was converted to SPSS code for 1998 and subsequent releases.

 /*  THE FOLLOWING CODE IS APPLIED TO THE DATA BEFORE THE PLI PROGRAM           */
 /*  IS EXECUTED.  THE PURPOSE OF THE CODE IS TO APPROPRIATELY RECODE           */
 /*  SELECTED 1979 AND 1980 VARIABLES.                                          */
 /*                                                                             */
 /* IF (R2283 EQ 0 OR R2282 EQ 0) THEN DO dlemo79=R2287 dleyr79=R2288 END       */
 /*  ELSE DO dlemo79=R169 dleyr79=R170 END                                      */
 /* IF (R4052 GT 0 AND R2283 NE 0 AND R2282 NE 0) THEN DO                       */
 /*  dlemo80=R2287 dleyr80=R2288 END                                            */
 /*  IF (R2275 EQ 0 OR R2276 EQ 0) THEN GRADE79=R2277                           */
 /*  ELSE GRADE79=R2286                                                         */
 /*  IF (R2280 GE 0) THEN hgcs79=R2280                                          */
 /*  ELSE                                                                       */
 /*  COMPUTE hgcs79=R173                                                        */
 /*  ENDIF                                                                      */
 /*  IF (R2276 EQ 0 AND R2286 GT 0) R156=1                                      */
 /*******************************************************************************/
 
 /* CREATE HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS AS OF 5-1-1998 */
 
COMPUTE HGC_CUR=-4
COMPUTE ENR_CUR=-4
 
DO REPEAT HGCS=HGCS2 TO HGCS17 
          /GRADE=GRADE2 TO GRADE17
          /WEIGHT=WEIGHT2 TO WEIGHT17
. DO IF (WEIGHT EQ 0)
. COMPUTE HGCS=-5
. COMPUTE GRADE=-5
. END IF
END REPEAT PRINT
 
DO IF (PUBID EQ 12073)
COMPUTE HGCS17=-5
COMPUTE GRADE17=-5
END IF
 
COMPUTE WGT1B=WEIGHT17
COMPUTE WGT2B=WEIGHT16
COMPUTE WGT3B=WEIGHT15
COMPUTE WGT4B=WEIGHT14
COMPUTE WGT5B=WEIGHT13
COMPUTE WGT6B=WEIGHT12
COMPUTE WGT7B=WEIGHT11
COMPUTE WGT8B=WEIGHT10
COMPUTE WGT9B=WEIGHT9
COMPUTE WGT10B=WEIGHT8
COMPUTE WGT11B=WEIGHT7
COMPUTE WGT12B=WEIGHT6
COMPUTE WGT13B=WEIGHT5
COMPUTE WGT14B=WEIGHT4
COMPUTE WGT15B=WEIGHT3
COMPUTE WGT16B=WEIGHT2
COMPUTE WGT17B=WEIGHT1
 
COMPUTE INTMO1B=INTMO17
COMPUTE INTMO2B=INTMO16
COMPUTE INTMO3B=INTMO15
COMPUTE INTMO4B=INTMO14
COMPUTE INTMO5B=INTMO13
COMPUTE INTMO6B=INTMO12
COMPUTE INTMO7B=INTMO11
COMPUTE INTMO8B=INTMO10
COMPUTE INTMO9B=INTMO9
COMPUTE INTMO10B=INTMO8
COMPUTE INTMO11B=INTMO7
COMPUTE INTMO12B=INTMO6
COMPUTE INTMO13B=INTMO5
COMPUTE INTMO14B=INTMO4
COMPUTE INTMO15B=INTMO3
COMPUTE INTMO16B=INTMO2
COMPUTE INTMO17B=INTMO1
 
COMPUTE INTYR1B=INTYR17
COMPUTE INTYR2B=INTYR16
COMPUTE INTYR3B=INTYR15
COMPUTE INTYR4B=INTYR14
COMPUTE INTYR5B=INTYR13
COMPUTE INTYR6B=INTYR12
COMPUTE INTYR7B=INTYR11
COMPUTE INTYR8B=INTYR10
COMPUTE INTYR9B=INTYR9
COMPUTE INTYR10B=INTYR8
COMPUTE INTYR11B=INTYR7
COMPUTE INTYR12B=INTYR6
COMPUTE INTYR13B=INTYR5
COMPUTE INTYR14B=INTYR4
COMPUTE INTYR15B=INTYR3
COMPUTE INTYR16B=INTYR2
COMPUTE INTYR17B=INTYR1
 
COMPUTE CURAT1B=CURAT17
COMPUTE CURAT2B=CURAT16
COMPUTE CURAT3B=CURAT15
COMPUTE CURAT4B=CURAT14
COMPUTE CURAT5B=CURAT13
COMPUTE CURAT6B=CURAT12
COMPUTE CURAT7B=CURAT11
COMPUTE CURAT8B=CURAT10
COMPUTE CURAT9B=CURAT9
COMPUTE CURAT10B=CURAT8
COMPUTE CURAT11B=CURAT7
COMPUTE CURAT12B=CURAT6
COMPUTE CURAT13B=CURAT5
COMPUTE CURAT14B=CURAT4
COMPUTE CURAT15B=CURAT3
COMPUTE CURAT16B=CURAT2
COMPUTE CURAT17B=CURAT1
 
COMPUTE DLEMO1B=DLEMO17
COMPUTE DLEMO2B=DLEMO16
COMPUTE DLEMO3B=DLEMO15
COMPUTE DLEMO4B=DLEMO14
COMPUTE DLEMO5B=DLEMO13
COMPUTE DLEMO6B=DLEMO12
COMPUTE DLEMO7B=DLEMO11
COMPUTE DLEMO8B=DLEMO10
COMPUTE DLEMO9B=DLEMO9
COMPUTE DLEMO10B=DLEMO8
COMPUTE DLEMO11B=DLEMO7
COMPUTE DLEMO12B=DLEMO6
COMPUTE DLEMO13B=DLEMO5
COMPUTE DLEMO14B=DLEMO4
COMPUTE DLEMO15B=DLEMO3
COMPUTE DLEMO16B=DLEMO2
COMPUTE DLEMO17B=DLEMO1
 
COMPUTE DLEYR1B=DLEYR17
COMPUTE DLEYR2B=DLEYR16
COMPUTE DLEYR3B=DLEYR15
COMPUTE DLEYR4B=DLEYR14
COMPUTE DLEYR5B=DLEYR13
COMPUTE DLEYR6B=DLEYR12
COMPUTE DLEYR7B=DLEYR11
COMPUTE DLEYR8B=DLEYR10
COMPUTE DLEYR9B=DLEYR9
COMPUTE DLEYR10B=DLEYR8
COMPUTE DLEYR11B=DLEYR7
COMPUTE DLEYR12B=DLEYR6
COMPUTE DLEYR13B=DLEYR5
COMPUTE DLEYR14B=DLEYR4
COMPUTE DLEYR15B=DLEYR3
COMPUTE DLEYR16B=DLEYR2
COMPUTE DLEYR17B=DLEYR1
 
COMPUTE HGCS1B=HGCS17
COMPUTE HGCS2B=HGCS16
COMPUTE HGCS3B=HGCS15
COMPUTE HGCS4B=HGCS14
COMPUTE HGCS5B=HGCS13
COMPUTE HGCS6B=HGCS12
COMPUTE HGCS7B=HGCS11
COMPUTE HGCS8B=HGCS10
COMPUTE HGCS9B=HGCS9
COMPUTE HGCS10B=HGCS8
COMPUTE HGCS11B=HGCS7
COMPUTE HGCS12B=HGCS6
COMPUTE HGCS13B=HGCS5
COMPUTE HGCS14B=HGCS4
COMPUTE HGCS15B=HGCS3
COMPUTE HGCS16B=HGCS2
COMPUTE HGCS17B=HGCS1
 
COMPUTE HGC1B=HGC17
COMPUTE HGC2B=HGC16
COMPUTE HGC3B=HGC15
COMPUTE HGC4B=HGC14
COMPUTE HGC5B=HGC13
COMPUTE HGC6B=HGC12
COMPUTE HGC7B=HGC11
COMPUTE HGC8B=HGC10
COMPUTE HGC9B=HGC9
COMPUTE HGC10B=HGC8
COMPUTE HGC11B=HGC7
COMPUTE HGC12B=HGC6
COMPUTE HGC13B=HGC5
COMPUTE HGC14B=HGC4
COMPUTE HGC15B=HGC3
COMPUTE HGC16B=HGC2
COMPUTE HGC17B=HGC1
 
DO REPEAT WEIGHT=WGT1B TO WGT17B   /* ASLI EQ NO */
         /INTMO=INTMO1B TO INTMO17B
         /CURAT=CURAT1B TO CURAT17B
         /DLEMO=DLEMO1B TO DLEMO17B
         /DLEYR=DLEYR1B TO DLEYR17B
         /INTYR=INTYR1B TO INTYR17B
         /HGCS=HGCS1B TO HGCS17B
         /HGC=HGC1B TO HGC17B
. LOOP IF (ASLI_CUR EQ 0 AND (HVDIP_C EQ -4 OR HVDIP_C EQ 0) AND FLAG98 EQ 1)
.   DO IF (HGC_CUR EQ -4 AND WEIGHT GT 0 AND INTMO GE 5 AND 
        (CURAT EQ 1 OR (DLEMO GE 5 AND DLEYR EQ INTYR)) AND HGCS GT HGC) 
.   COMPUTE HGC_CUR=HGCS
.   ELSE IF (HGC_CUR EQ -4 AND WEIGHT GT 0)
.   COMPUTE HGC_CUR=HGC
.   END IF
. END LOOP IF (WEIGHT GT 0 AND HGC_CUR NE -4 AND FLAG98 EQ 0)
END REPEAT PRINT
DO IF (HGC_CUR GE 12) 
COMPUTE ENR_CUR=4
ELSE IF (HGC_CUR GE 0)
COMPUTE ENR_CUR=1
END IF
 
DO IF (ASLI_CUR EQ 1 AND FLAG98 EQ 1 AND HGCS_CUR LE 0)  /*ASLI EQ YES */
                                                   /* HGC_CUR STILL -4 */
.   DO IF (CURAT_C EQ 1 AND GRADE_C GE 1) /* CURAT AND GRADE */
.   COMPUTE HGC_CUR=(GRADE_C - 1)
.       DO IF (HGC_CUR GE 12) 
.       COMPUTE ENR_CUR=3
.       ELSE
.       COMPUTE ENR_CUR=2
.       END IF 
.   ELSE IF (CURAT_C EQ 0 AND HGA_CUR GE 1)  /* NOT CURAT BUT GRADE */
.     DO IF (DLEYR_C LT LASTYR OR DLEMO_C LT 5)  /* DATES */
.     COMPUTE HGC_CUR=HGA_CUR
.       DO IF (HGC_CUR GE 12) 
.       COMPUTE ENR_CUR=4
.       ELSE
.       COMPUTE ENR_CUR=1
.       END IF
.     END IF  /* DATES */
.   ELSE
.   COMPUTE HGC_CUR=(HGA_CUR - 1)
.     DO IF (HGC_CUR GE 12)
.     COMPUTE ENR_CUR=4
.     ELSE 
.     COMPUTE ENR_CUR=1
.     END IF    /* DATES OK */
.   END IF      /* NOTCURAT BUT GRADE */ /* HGC_CUR STILL -4 */
ELSE IF (ASLI_CUR EQ 1 AND FLAG98 EQ 1 AND 
     (HGCS_CUR EQ HGA_CUR OR HGCS_CUR EQ GRADE_C)) /* ENROLL */
.   DO IF ((DLEYR_C EQ CURANTYR AND DLEMO_C GE 5) OR (INTMO_C GE 5 AND
                 CURAT_C EQ 1))
.   COMPUTE HGC_CUR=(HGCS_CUR - 1)
.     DO IF (HGC_CUR GE 12)
.     COMPUTE ENR_CUR=3
.     ELSE
.     COMPUTE ENR_CUR=2
.     END IF
.   ELSE
.   COMPUTE HGC_CUR=HGCS_CUR
.       DO IF (HGC_CUR GE 12) 
.       COMPUTE ENR_CUR=4
.       ELSE
.       COMPUTE ENR_CUR=1
.       END IF
.   END IF
ELSE IF (ASLI_CUR EQ 1 AND FLAG98 EQ 1 AND 
         (HGCS_CUR EQ (HGA_CUR-1) OR HGCS_CUR EQ (GRADE_C-1)))
COMPUTE HGC_CUR=HGCS_CUR
. DO IF (ENR_CUR EQ -4 AND CURAT_C EQ 1 AND HGC_CUR GE 0)
.   DO IF (HGC_CUR GE 12)
.   COMPUTE ENR_CUR=3
.   ELSE
.   COMPUTE ENR_CUR=2
.   END IF
. ELSE IF (ENR_CUR EQ -4 AND CURAT_C EQ 0 AND HGC_CUR GE 0)
.   DO IF (HGC_CUR GE 12)
.   COMPUTE ENR_CUR=4
.   ELSE
.   COMPUTE ENR_CUR=1
.   END IF
. END IF
ELSE IF (ASLI_CUR EQ 1 AND FLAG98 EQ 1 AND
           ((HGCS_CUR LT HGA_CUR AND HGA_CUR GT 0 AND HGA_CUR LT 20) OR
             (HGCS_CUR LT GRADE_C AND GRADE_C GT 0 AND GRADE_C LT 20))) 
COMPUTE HGC_CUR=HGCS_CUR 
. DO IF (ENR_CUR EQ -4 AND CURAT_C EQ 1 AND HGC_CUR GE 0)
.   DO IF (HGC_CUR GE 12)
.   COMPUTE ENR_CUR=3
.   ELSE
.   COMPUTE ENR_CUR=2
.   END IF
. ELSE IF (ENR_CUR EQ -4 AND CURAT_C EQ 0 AND HGC_CUR GE 0)
.   DO IF (HGC_CUR GE 12)
.   COMPUTE ENR_CUR=4
.   ELSE
.   COMPUTE ENR_CUR=1
.   END IF
. END IF
END IF /* ASLI EQ YES */
 
FREQUENCIES VARIABLES=HGC_CUR ENR_CUR /FORMAT=ONEPAGE
 
DO IF (((HGC_CUR EQ 10 OR HGC_CUR EQ 11) AND (HVDIP_C EQ 1 OR ATTCOL_C EQ 1)) OR
       (DIP_CUR EQ 2 AND HGC_CUR LT 12) OR 
       (HGC_CUR EQ -4 AND (DIP_CUR EQ 1 OR DIP_CUR EQ 3)))
COMPUTE HGC_CUR=12
.  DO IF (ENR_CUR GT 0)
.  COMPUTE ENR_CUR=(5-ENR_CUR)
.  ELSE IF (CURAT_C EQ 1 OR (DLEYR_C EQ LASTYR AND DLEMO_C GE 5))
.  COMPUTE ENR_CUR=3
.  ELSE
.  COMPUTE ENR_CUR=4
.  END IF
ELSE IF (HGC_CUR LT 0 AND DIP_CUR EQ -3)
COMPUTE HGC_CUR=-3
COMPUTE ENR_CUR=-3
END IF
 
DO IF (HGC_CUR GT 20)
COMPUTE HGC_CUR=-3
COMPUTE ENR_CUR=-3
END IF
 
DO IF (HGC_CUR GT (HGC_DLI + 3) AND HGC_DLI GT 0 AND DIP_CUR NE 2 AND DIP_CUR NE 3)
COMPUTE HGC_CUR=-3
COMPUTE ENR_CUR=-3
END IF
 
DO IF ((HGC_CUR GT 0 AND HGC_CUR LT (HGC_DLI - 1)) OR 
        (HGC_DLI EQ 12 AND HGC_CUR EQ 11))
COMPUTE HGC_CUR=-3
COMPUTE ENR_CUR=-3
END IF
 
 
       /* END LOOP NEW IN 96 OLD AND NEW FILES HAVE ONLY INTERVIEWS */
                /*      IF THERE IS A NEED TO UNCOMMENT THIS END     */
 
COMPUTE TRU=0
 
DO REPEAT DIP=DIP1 TO DIP17
IF (DIP GT 1) TRU=1
IF (TRU EQ 1 AND HGC_CUR LT 12) HGC_CUR=12
IF (TRU EQ 1 AND (ENR_CUR EQ 1 OR ENR_CUR LT 0)) ENR_CUR=4
IF (HGC_CUR EQ -3 AND ENR_CUR EQ -4) ENR_CUR=-3
END REPEAT 
 
DO IF (FLAG98 EQ 0)
COMPUTE HGC_CUR=-5
COMPUTE ENR_CUR=-5
END IF
 
DO IF (HGC_CUR EQ -4 AND FLAG98 EQ 1)
COMPUTE HGC_CUR=-3
END IF
 
DO IF (ENR_CUR EQ -4 AND FLAG98 EQ 1)
COMPUTE ENR_CUR=-3
END IF
 
/*  EACH INSTANCE OF -3 FOR HIGHEST GRADE COMPLETED AND ENROLLMENT           */
/*STATUS IS REVIEWED BY CHECKING SELECTED SCHOOL VARIABLES.  VALUES OF -3    */
/* ARE RECODED TO VALID VALUES WHERE AUXILLIARY INFORMATION INDICATES.       */
/*  HOWEVER, THERE ARE A NUMBER OF -3S COMPUTED FOR HIGHEST GRADE            */
/*  COMPLETED AND ENROLLMENT STATUS THAT REMAIN.                             */

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of MAY 1, 2000

NOTE: The PL/1 code used to create Highest Grade Completed and Enrollment Status variables through the 1996 release was converted to SPSS code for the 1998 and 2000 releases.

/* The following code is applied to the data before the pli program is executed. */
/* The purpose of the code is to appropriately recode selected 1979 and 1980     */
/* variables.                                                                    */
/* if (R2283 eq 0 or R2282 eq 0) then do dlemo79=R2287 dleyr79=R2288 end         */
/*      else do dlemo79=R169 dleyr79=R170 end                                    */
/* if (R4052 gt 0 and R2283 ne 0 and R2282 ne 0)                                 */
/*      then do dlemo80=R2287 dleyr80=R2288 end                                  */
/* if (R2275 eq 0 or R2276 eq 0) then GRADE79=R2277 else GRADE79=R2286           */
/* if (R2280 ge 0) then hgcs79=R2280 else compute hgcs79=R173                    */
/* ENDIF                                                                         */
/* if (R2276 eq 0 and R2286 gt 0) R156=1                                         */
/*********************************************************************************/
/* CREATE HIGHEST GRADE COMPLETED AND ENROLLMENT STATUS AS OF 5-1-2000 */
 
compute hgc_cur=-4
compute enr_cur=-4
 
do repeat hgcs=hgcs2 to hgcs18
/grade=grade2 to grade18
/weight=weight2 to weight18
. do if (weight eq 0)
. compute hgcs=-5
. compute grade=-5
. end if
end repeat print
 
compute wgt1b=weight18
compute wgt2b=weight17
compute wgt3b=weight16
compute wgt4b=weight15
compute wgt5b=weight14
compute wgt6b=weight13
compute wgt7b=weight12
compute wgt8b=weight11
compute wgt9b=weight10
compute wgt10b=weight9
compute wgt11b=weight8
compute wgt12b=weight7
compute wgt13b=weight6
compute wgt14b=weight5
compute wgt15b=weight4
compute wgt16b=weight3
compute wgt17b=weight2
compute wgt18b=weight1
 
compute intmo1b=intmo18
compute intmo2b=intmo17
compute intmo3b=intmo16
compute intmo4b=intmo15
compute intmo5b=intmo14
compute intmo6b=intmo13
compute intmo7b=intmo12
compute intmo8b=intmo11
compute intmo9b=intmo10
compute intmo10b=intmo9
compute intmo11b=intmo8
compute intmo12b=intmo7
compute intmo13b=intmo6
compute intmo14b=intmo5
compute intmo15b=intmo4
compute intmo16b=intmo3
compute intmo17b=intmo2
compute intmo18b=intmo1
 
compute intyr1b=intyr18
compute intyr2b=intyr17
compute intyr3b=intyr16
compute intyr4b=intyr15
compute intyr5b=intyr14
compute intyr6b=intyr13
compute intyr7b=intyr12
compute intyr8b=intyr11
compute intyr9b=intyr10
compute intyr10b=intyr9
compute intyr11b=intyr8
compute intyr12b=intyr7
compute intyr13b=intyr6
compute intyr14b=intyr5
compute intyr15b=intyr4
compute intyr16b=intyr3
compute intyr17b=intyr2
compute intyr18b=intyr1
 
compute curat1b=curat18
compute curat2b=curat17
compute curat3b=curat16
compute curat4b=curat15
compute curat5b=curat14
compute curat6b=curat13
compute curat7b=curat12
compute curat8b=curat11
compute curat9b=curat10
compute curat10b=curat9
compute curat11b=curat8
compute curat12b=curat7
compute curat13b=curat6
compute curat14b=curat5
compute curat15b=curat4
compute curat16b=curat3
compute curat17b=curat2
compute curat18b=curat1
 
compute dlemo1b=dlemo18
compute dlemo2b=dlemo17
compute dlemo3b=dlemo16
compute dlemo4b=dlemo15
compute dlemo5b=dlemo14
compute dlemo6b=dlemo13
compute dlemo7b=dlemo12
compute dlemo8b=dlemo11
compute dlemo9b=dlemo10
compute dlemo10b=dlemo9
compute dlemo11b=dlemo8
compute dlemo12b=dlemo7
compute dlemo13b=dlemo6
compute dlemo14b=dlemo5
compute dlemo15b=dlemo4
compute dlemo16b=dlemo3
compute dlemo17b=dlemo2
compute dlemo18b=dlemo1
 
compute dleyr1b=dleyr18
compute dleyr2b=dleyr17
compute dleyr3b=dleyr16
compute dleyr4b=dleyr15
compute dleyr5b=dleyr14
compute dleyr6b=dleyr13
compute dleyr7b=dleyr12
compute dleyr8b=dleyr11
compute dleyr9b=dleyr10
compute dleyr10b=dleyr9
compute dleyr11b=dleyr8
compute dleyr12b=dleyr7
compute dleyr13b=dleyr6
compute dleyr14b=dleyr5
compute dleyr15b=dleyr4
compute dleyr16b=dleyr3
compute dleyr17b=dleyr2
compute dleyr18b=dleyr1
 
compute hgcs1b=hgcs18
compute hgcs2b=hgcs17
compute hgcs3b=hgcs16
compute hgcs4b=hgcs15
compute hgcs5b=hgcs14
compute hgcs6b=hgcs13
compute hgcs7b=hgcs12
compute hgcs8b=hgcs11
compute hgcs9b=hgcs10
compute hgcs10b=hgcs9
compute hgcs11b=hgcs8
compute hgcs12b=hgcs7
compute hgcs13b=hgcs6
compute hgcs14b=hgcs5
compute hgcs15b=hgcs4
compute hgcs16b=hgcs3
compute hgcs17b=hgcs2
compute hgcs18b=hgcs1
 
compute hgc1b=hgc18
compute hgc2b=hgc17
compute hgc3b=hgc16
compute hgc4b=hgc15
compute hgc5b=hgc14
compute hgc6b=hgc13
compute hgc7b=hgc12
compute hgc8b=hgc11
compute hgc9b=hgc10
compute hgc10b=hgc9
compute hgc11b=hgc8
compute hgc12b=hgc7
compute hgc13b=hgc6
compute hgc14b=hgc5
compute hgc15b=hgc4
compute hgc16b=hgc3
compute hgc17b=hgc2
compute hgc18b=hgc1
 
do repeat weight=wgt1b to wgt18b
/* asli eq no */
/intmo=intmo1b to intmo18b
/curat=curat1b to curat18b
/dlemo=dlemo1b to dlemo18b
/dleyr=dleyr1b to dleyr18b
/intyr=intyr1b to intyr18b
/hgcs=hgcs1b to hgcs18b
/hgc=hgc1b to hgc18b
 
. loop if (asli_cur eq 0 and (hvdip_c eq -4
or hvdip_c eq 0) and flag00 eq 1)
. do if (hgc_cur eq -4 and weight gt 0 and intmo ge 5
and (curat eq 1 or (dlemo ge 5 and dleyr eq intyr))
and hgcs gt hgc)
. compute hgc_cur=hgcs
. else if (hgc_cur eq -4 and weight gt 0)
. compute hgc_cur=hgc
. end if
. end loop if (weight gt 0 and hgc_cur ne -4 and flag00 eq 0)
end repeat print
 
do if (hgc_cur ge 12)
compute enr_cur=4
else if (hgc_cur ge 0)
compute enr_cur=1
end if
 
do if (asli_cur eq 1 and flag00 eq 1
and hgcs_cur le 0)
/*asli eq yes */ /* hgc_cur still -4 */
. do if (curat_c eq 1 and grade_c ge 1)
/* curat and grade */
. compute hgc_cur=(grade_c - 1)
. do if (hgc_cur ge 12)
. compute enr_cur=3
. else
. compute enr_cur=2
. end if
 
. else if (curat_c eq 0 and hga_cur ge 1)
/* not curat but grade */
. do if (dleyr_c lt lastyr or dlemo_c lt 5)
. compute hgc_cur=hga_cur
/* dates */
. do if (hgc_cur ge 12)
. compute enr_cur=4
. else
. compute enr_cur=1
. end if
 
. end if
 
/* dates */
. else
. compute hgc_cur=(hga_cur - 1)
. do if (hgc_cur ge 12)
. compute enr_cur=4
. else
. compute enr_cur=1
. end if
 
/* dates ok */
. end if
 
/* notcurat but grade */ /* hgc_cur still -4 */
else if (asli_cur eq 1 and flag00 eq 1
and (hgcs_cur eq hga_cur or hgcs_cur eq grade_c))
/* enroll */
. do if ((dleyr_c eq curantyr
and dlemo_c ge 5) or (intmo_c ge 5
and curat_c eq 1))
. compute hgc_cur=(hgcs_cur - 1)
. do if (hgc_cur ge 12)
. compute enr_cur=3
. else
. compute enr_cur=2
. end if
 
. else
. compute hgc_cur=hgcs_cur
. do if (hgc_cur ge 12)
. compute enr_cur=4
. else
. compute enr_cur=1
. end if
 
. end if
 
else if (asli_cur eq 1 and flag00 eq 1
and (hgcs_cur eq (hga_cur-1)
or hgcs_cur eq (grade_c-1)))
compute hgc_cur=hgcs_cur
. do if (enr_cur eq -4 and curat_c eq 1
and hgc_cur ge 0)
. do if (hgc_cur ge 12)
. compute enr_cur=3
. else
. compute enr_cur=2. end if
. else if (enr_cur eq -4
and curat_c eq 0 and hgc_cur ge 0)
. do if (hgc_cur ge 12)
. compute enr_cur=4
. else
. compute enr_cur=1.
end if
 
. end if
 
else if (asli_cur eq 1 and flag00 eq 1
and ((hgcs_cur lt hga_cur and hga_cur gt 0
and hga_cur lt 20) or (hgcs_cur lt grade_c
and grade_c gt 0 and grade_c lt 20)))
compute hgc_cur=hgcs_cur
. do if (enr_cur eq -4 and curat_c eq 1
and hgc_cur ge 0)
. do if (hgc_cur ge 12)
. compute enr_cur=3
. else
. compute enr_cur=2.
end if
 
. else if (enr_cur eq -4
and curat_c eq 0 and hgc_cur ge 0)
. do if (hgc_cur ge 12)
. compute enr_cur=4
. else
. compute enr_cur=1.
end if
 
. end if
 
end if
/* asli eq yes */
 
do if (((hgc_cur eq 10 or hgc_cur eq 11)
and (hvdip_c eq 1 or attcol_c eq 1))
or (dip_cur eq 2 and hgc_cur lt 12)
or (hgc_cur eq -4 and (dip_cur eq 1
or dip_cur eq 3)))
compute hgc_cur=12
. do if (enr_cur gt 0)
. compute enr_cur=(5-enr_cur)
. else if (curat_c eq 1
or (dleyr_c eq lastyr and dlemo_c ge 5))
. compute enr_cur=3
. else
. compute enr_cur=4
. end if
else if (hgc_cur lt 0 and dip_cur eq -3)
compute hgc_cur=-3
 
compute enr_cur=-3
end if
do if (hgc_cur gt 20)
compute hgc_cur=-3
compute enr_cur=-3
end if
 
do if (hgc_cur gt (hgc_dli + 3)
and hgc_dli gt 0 and dip_cur ne 2
and dip_cur ne 3)
compute hgc_cur=-3
compute enr_cur=-3
end if
do if ((hgc_cur gt 0 and hgc_cur lt (hgc_dli - 1))
or (hgc_dli eq 12 and hgc_cur eq 11))
compute hgc_cur=-3
compute enr_cur=-3
end if
 
compute tru=0
do repeat dip=dip1 to dip18
if (dip gt 1) tru=1
if (tru eq 1 and hgc_cur lt 12) hgc_cur=12
if (tru eq 1 and (enr_cur eq 1 or enr_cur lt 0)) enr_cur=4
if (hgc_cur eq -3 and enr_cur eq -4) enr_cur=-3
end repeat print
do if (flag00 eq 0)
compute hgc_cur=-5
compute enr_cur=-5
end if
 
do if (hgc_cur eq -4 and flag00 eq 1)
compute hgc_cur=-3
end if
 
do if (enr_cur eq -4 and flag00 eq 1)
compute enr_cur=-3
end if
 
/* HGC_00=R(70071.) */
/* ENROLL_00=R(70072.) */
 
/* Each instance of -3 for highest grade completed and enrollment status is 
reviewed by checking selected school variables. Values of -3 are recoded to 
valid values where auxilliary information indicates. However, there are a 
number of -3s computed for highest grade completed and enrollment status 
that remain. */
 

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of  May 1, 2002

NOTE: The SPSS code used to create Highest Grade Completed and Enrollment Status variables for the 1998 and 2000 releases was converted to SAS code for 2002 and subsequent releases.

/*
Creates the following variables:
hgc_cur - Highest Grade Completed as of May 1, Survey Year
enr_cur - Enrollment Status as of May 1, Survey Year
hgcRev_cur - Highest Grade Completed as of May 1, Survey Year - revised
enrRev_cur - Enrollment Status as of May 1, Survey Year - revised;
*/
 
flag02=1;
 
* Hand edits 2002 - taken from the code in hands_edits_hgc_vars file;
if (pubid = 494) then do;
sep02_in=1; end;
else if (pubid = 1347) then do;
apr02_in=1; end;
else if (pubid = 148) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; end;
else if (pubcid = 2016) then do;
jun02_in=1; end;
else if (pubid = 2330) then do;
may02_in=1; jun02_in=1; end;
else if (pubid = 2565) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; may02_in=1; jun02_in=1; end;
else if (pubid = 2727) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; may02_in=1; jun02_in=1; 
jul02_in=1; aug02_in=1; sep02_in=1; end;
else if (pubid = 3592) then do;
jan02_in=1; feb02_in=1; mar02_in=1; end;
else if (pubid = 3718) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; may02_in=1; jun02_in=1; 
jul02_in=1; aug02_in=1; sep02_in=1; oct02_in=1; end;
else if (pubid = 3779) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; may02_in=1; end;
else if (pubid = 3894) then do;
feb02_in=1; mar02_in=1; apr02_in=1; may02_in=1; end;
else if (pubid = 3995) then do;
may02_in=1; jun02_in=1; end;
else if (pubid = 4426) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; may02_in=1; end;
else if (pubid = 4834) then do;
aug02_in=1; sep02_in=1; end;
else if (pubid = 5827) then do;
jan02_in=1; end;
else if (pubid = 5984) then do;
may02_in=1; jun02_in=1; jul02_in=1; end;
else if (pubid = 5998) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; may02_in=1; jun02_in=1; end;
else if (pubid = 6032) then do;
may02_in=1; jun02_in=1; jul02_in=1; aug02_in=1; sep02_in=1; oct02_in=1; 
nov02_in=1; end;
else if (pubid = 7081) then do;
jul02_in=1; end;
else if (pubid = 8930) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; end;
else if (pubid = 9840) then do;
may02_in=1; end;
else if (pubid = 10195) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; may02_in=1; end;
else if (pubid = 10335) then do;
jan02_in=1; feb02_in=1; mar02_in=1; end;
else if (pubid = 10799) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; end;
else if (pubid = 12113) then do;
jan02_in=1; feb02_in=1; mar02_in=1; apr02_in=1; may02_in=1; jun02_in=1; end;
 
* Get the index of the last year+month when enrolled;
maxI = 0;
do i = dim(myIn) to 1 by -1;
if myIn(i) = 1 then do; maxI = i; leave; end;
end;
 
* Transform maximal myIn index into the corresponding year and month;
if (maxI ~= 0) then do;
dleMo_ca = mod(maxI-1,12)+1;
dleYr_ca = 1999 + floor((maxI-1)/12);
else if (curat_c = 1) then do; dleMo_ca=q_1c_ms;
dleYr_ca=2002;
end;
else do;
dleMo_ca = -4;
dleYr_ca = -4;
end;
 
*------------------------------------------------------------------------------;
* Create variables for current year and last survey year;
 
hgc_dli=hgc19; *highest grade completed since the date of the last interview;
curantYr=2002; *current survey year;
lastYr=2000; *last year;
*lastRnd=19; *last round;
 
*------------------------------------------------------------------------------;
* Make dleYr Y2K-compliant (e.g. 74 -> 1974);
 
array dleYr (*) dleyr1 - dleyr15;
array weight (*) weight1 - weight15;
 
do i = 1 to dim(dleYr);
if (weight(i) > 0 and 0 < dleYr(i) < 100)
then dleYr(i) = dleYr(i) + 1900;
end;
 
 
*==============================================================================;
* ;
* Create Highest Grade Completed and Enrollment Status as of 5-1-2002 ;
* ;
*==============================================================================;
 
data main;
set Merged (drop= i);
 
*------------------------------------------------------------------------------;
* Create arrays;
 
array weightA (*) weight1 - weight19;
array intMoA (*) intMo1 - intMo19;
array dleMoA (*) dleMo1 - dleMo19;
array dleYrA (*) dleYr1 - dleYr19;
array curAtA (*) curAt1 - curAt19;
array hgcSA (*) hgcs1 - hgcs19;
array hgcA (*) hgc1 - hgc19;
array dipA (*) dip1 - dip19;
 
array intYrA (19) _TEMPORARY_ (1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 
1989 1990 1991 1992 1993 1994 1996 1998 2000);
 
hgc_cur=-4; *current highest grade completed;
enr_cur=-4; *current enrollment status;
 
*------------------------------------------------------------------------------;
* Set HGC(i) and HGCS(i) to -5 if Weight = 0 ;
 
do i = 2 to dim(hgcA);
if (weightA(i) = 0) then do;
hgcA(i) = -5;
hgcsA(i) = -5;
end;
end;
 
*------------------------------------------------------------------------------;
* Set hgc_cur to hgcs(i) or hgc(i) under certain circumstances;
 
do i = dim(hgcA) to 1 by -1;
if (asli_cur = 0 and /* did not attended school since last interview */
(hvdip_c = -4 or hvdip_c = 0) and /* does not have HS diploma */
flag02 = 1) then do;
if (hgc_cur = -4 and weightA(i) > 0) then do; /* HGC current */
if (IntMoA(i) >= 5 and /* Interviewed in May+ */
(CurAtA(i) = 1 or (DLEMoA(i) >= 5 and DLEYrA(i) = IntYrA(i))) and
/* Currently in school or was in school after May */
HgcSA(i) > HgcA(i) )
then hgc_cur = HgcSA(i);
else hgc_cur = HgcA(i);
end;
end;
end;
 
*------------------------------------------------------------------------------;
* Set enr_cur;
 
if (hgc_cur >= 12)
then enr_cur = 4;
else if (hgc_cur >= 0)
then enr_cur = 1;
 
*------------------------------------------------------------------------------;
* Macros to set hgc_cur & enr_cur based on asli_cur, hgcs_cur, hga_cur, grade_c;
 
%Macro setEnrCur32(aHGC_Cur, aENR_Cur);
do; if (&aHGC_Cur >= 12)
then &aEnr_Cur = 3;
else &aEnr_Cur = 2;
end;
%MEnd;
 
%Macro setEnrCur41(aHGC_Cur, aENR_Cur);
do; if (&aHGC_Cur >= 12)
then &aEnr_Cur = 4;
else &aEnr_Cur = 1;
end;
%MEnd;
 
if (asli_cur = 1 and flag02 = 1) then do;
if (hgcs_cur <= 0) then do;
if (curat_c = 1 and grade_c >= 1) then do;
hgc_cur=(grade_c - 1);
%setEnrCur32(hgc_cur, enr_cur);
end;
else if (curat_c = 0 and hga_cur >= 1) then do;
if (dleyr_ca < lastyr or dlemo_ca < 5) then do;
hgc_cur=hga_cur;
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
else do;
hgc_cur=(hga_cur - 1);
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
else if ((hgcs_cur = hga_cur or hgcs_cur = grade_c)) then do;
if ((dleyr_ca = curantyr and dlemo_ca >= 5)
or (intmo_c >= 5 and curat_c = 1)) then do;
hgc_cur=(hgcs_cur - 1);
%setEnrCur32(hgc_cur, enr_cur);
end;
else do;
hgc_cur=hgcs_cur;
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
else if ((hgcs_cur = (hga_cur-1)) or
(hgcs_cur = (grade_c-1)) or
(hgcs_cur < hga_cur and 0 < hga_cur < 20) or
(hgcs_cur < grade_c and 0 < grade_c < 20)) then do;
hgc_cur=hgcs_cur;
if (enr_cur = -4 and curat_c = 1 and hgc_cur >= 0) then do;
%setEnrCur32(hgc_cur, enr_cur);
end;
else if (enr_cur = -4 and curat_c = 0 and hgc_cur >= 0) then do;
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
end;
 
 
*------------------------------------------------------------------------------;
 
if ( ((hgc_cur = 10 or hgc_cur = 11) and (hvdip_c = 1 or attcol_c = 1)) or
(dip_cur = 2 and hgc_cur < 12) or
(hgc_cur = -4 and (dip_cur = 1 or dip_cur = 3))) then do;
hgc_cur=12;
if (enr_cur > 0) then
enr_cur = 5 - enr_cur;
else if (curat_c = 1 or (dleyr_ca = lastYr and dlemo_ca >= 5))then
enr_cur = 3;
else
enr_cur = 4;
end;
else if (hgc_cur < 0 and dip_cur = -3) then do;
hgc_cur=-3; enr_cur=-3;
end;
 
*------------------------------------------------------------------------------;
 
if ( (hgc_cur > 20) or
(hgc_cur > hgc_dli + 3 & hgc_dli > 0 & dip_cur ~= 2 & dip_cur ~= 3) or
(hgc_cur > 0 & hgc_dli - 1 > hgc_cur) or
(hgc_cur = 11 & hgc_dli = 12 )) then do;
hgc_cur=-3;
enr_cur=-3;
end;
 
*------------------------------------------------------------------------------;
 
tru=0; * true: 0 - does not have HS diploma (ever), 1 does have a HS diploma;
 
if (hgc_cur = -3 and enr_cur = -4) then enr_cur=-3;
 
do i = 1 to dim(dipA);
if (dipA(i) > 1) then do;
tru=1;
if (hgc_cur < 12) then hgc_cur=12; * has HS diploma => has HGC >= 12;
if (enr_cur = 1 or enr_cur < 0) then enr_cur=4;
leave;
end;
end;
 
*------------------------------------------------------------------------------;
 
if (flag02 = 0) then do;
hgc_cur=-5; enr_cur=-5;
hgcRev_cur=-5; enrrev_cur=-5;
end;
 
if (flag02 = 1) then do;
if (hgc_cur = -4) then hgc_cur=-3;
if (enr_cur = -4) then enr_cur=-3;
end;
 
*=============================================================================;
* ;
* Create revised variables ;
* ;
*=============================================================================;
/* The revised variables take into account more accurately past reports of HGC to 
eliminate regressive changes in HGC (for instance, preventing someone who has
previously reported completing 18 years of schooling, and is now working on an
undergraduate level in some area from being coded lower than 18) */
 
/* maxGrd - the highest HGC value ever computed */
maxGrd=hgc_cur;
do i = 1 to dim(hgcA);
if (weightA(i) > 0 & hgcA(i) > maxGrd) then
maxGrd = hgcA(i);
end;
 
if (hgc_cur = -5) then maxGrd = -5;
 
hgcRev_cur = maxGrd;
enrRev_cur = enr_cur;

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of May 1, 2004

*------------------------------------------------------------------------------------------;
* Calculate date last enrolled;

array myIn (*)
jan02_in feb02_in mar02_in apr02_in may02_in jun02_in jul02_in aug02_in sep02_in oct02_in nov02_in dec02_in
jan03_in feb03_in mar03_in apr03_in may03_in jun03_in jul03_in aug03_in sep03_in oct03_in nov03_in dec03_in
jan04_in feb04_in mar04_in apr04_in may04_in jun04_in jul04_in aug04_in sep04_in oct04_in nov04_in dec04_in;

* Get the index of the last year+month when enrolled;
maxI = 0;
do i = dim(myIn) to 1 by -1; *If SAS array 0 based indexes this would be simpler;
if myIn(i) = 1 then do; maxI = i; leave; end;
end;

* Transform maximal myIn index into the corresponding year and month;
if (maxI ~= 0) then do;
dleMo_ca = mod(maxI-1,12)+1;
dleYr_ca = 2002 + floor((maxI-1)/12); * like div: = 2002 + (maxI-1) div 12 ;
end;
else if (curat_c = 1) then do; * taken from the code in hands_edits_hgc_vars file;
dleMo_ca=q_1c_ms;
dleYr_ca=2004;
end;
else do;
dleMo_ca = -4;
dleYr_ca = -4;
end;

proc sort; by pubid;

*------------------------------------------------------------------------------------------;
* Create variables about the current year and the last interview;

hgc_dli=hgc20; *highest grade completed since the date of the last interview;
curantYr=2004; *current ?? year;
lastYr=2002; *last year;
*lastRnd=20; *last round - Not used;

*------------------------------------------------------------------------------------------;
* Make dates reported in 1993 and prior years dleYr Y2K-compliant (e.g. 74 -> 1974);

array dleYr (*) dleyr1 - dleyr15;
array weight (*) weight1 - weight15;

do i = 1 to dim(dleYr);
if (weight(i) > 0 and 0 < dleYr(i) < 100)
then dleYr(i) = dleYr(i) + 1900;
end;

proc sort; by pubid;

*===============================================================================;
* ;
* Create Highest Grade Completed and Enrollment Status as of 5-1-2004 ;
* ;
*===============================================================================;

data main;
set Merged (drop= i);

*-------------------------------------------------------------------------------;
* Create all the necessary arrays;

array weightA (*) weight1 - weight20;
array intMoA (*) intMo1 - intMo20;
array dleMoA (*) dleMo1 - dleMo20;
array dleYrA (*) dleYr1 - dleYr20;
array curAtA (*) curAt1 - curAt20;
array hgcSA (*) hgcs1 - hgcs20;
array hgcA (*) hgc1 - hgc20;
array dipA (*) dip1 - dip20;

array intYrA (20) _TEMPORARY_ (1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 /* Interview years */
1990 1991 1992 1993 1994 1996 1998 2000 2002);

hgc_cur=-4; *current highest grade completed;
enr_cur=-4; *current enrollment status;

*-------------------------------------------------------------------------------;
* Set HGC(i) and HGCS(i) to -5 if Weight = 0 ;

/* TODO: Why only from 2? */
do i = 2 to dim(hgcA);
if (weightA(i) = 0) then do;
hgcA(i) = -5;
hgcsA(i) = -5;
end;
end;

*-------------------------------------------------------------------------------;
* Sometimes (?), set hgc_cur to hgcs(i) or hgc(i);

do i = dim(hgcA) to 1 by -1;
if (asli_cur = 0 and /* did not attended school since last interview */
(hvdip_c = -4 or hvdip_c = 0) and /* does not have HS diploma */
flag04 = 1) then do; /* ! Originally was a loop in SPSS */

if (hgc_cur = -4 and weightA(i) > 0) then do; /* Highest Grade completed current */
if ( IntMoA(i) >= 5 and /* Interviewed in May+ */
(CurAtA(i) = 1 or (DLEMoA(i) >= 5 and DLEYrA(i) = IntYrA(i))) and /* Currently in school or was in school after May */
HgcSA(i) > HgcA(i) )
then hgc_cur = HgcSA(i);
else hgc_cur = HgcA(i);
end;
/*if ((flag04 = 0) and (hgc_cur ~= -4) and (Weight(i) > 0)) then leave; - works without it*/
end;
end;

*-------------------------------------------------------------------------------;

if (hgc_cur >= 12)
then enr_cur = 4;
else if (hgc_cur >= 0)
then enr_cur = 1;

*-------------------------------------------------------------------------------;


%Macro setEnrCur32(aHGC_Cur, aENR_Cur);
do; if (&aHGC_Cur >= 12)
then &aEnr_Cur = 3;
else &aEnr_Cur = 2;
end;
%MEnd;

%Macro setEnrCur41(aHGC_Cur, aENR_Cur);
do; if (&aHGC_Cur >= 12)
then &aEnr_Cur = 4;
else &aEnr_Cur = 1;
end;
%MEnd;

if (asli_cur = 1 and flag04 = 1) then do;
if (hgcs_cur <= 0) then do;
if (curat_c = 1 and grade_c >= 1) then do;
hgc_cur=(grade_c - 1);
%setEnrCur32(hgc_cur, enr_cur);
end;
else if (curat_c = 0 and hga_cur >= 1) then do;
if (dleyr_ca < lastyr or dlemo_ca < 5) then do;
hgc_cur=hga_cur;
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
else do;
hgc_cur=(hga_cur - 1);
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
else if ((hgcs_cur = hga_cur or hgcs_cur = grade_c)) then do;
if ((dleyr_ca = curantyr and dlemo_ca >= 5) or (intmo_c >= 5 and curat_c = 1)) then do;
hgc_cur=(hgcs_cur - 1);
%setEnrCur32(hgc_cur, enr_cur);
end;
else do;
hgc_cur=hgcs_cur;
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
else if ((hgcs_cur = (hga_cur-1)) or
(hgcs_cur = (grade_c-1)) or
(hgcs_cur < hga_cur and 0 < hga_cur < 20) or
(hgcs_cur < grade_c and 0 < grade_c < 20)) then do;
hgc_cur=hgcs_cur;
if (enr_cur = -4 and curat_c = 1 and hgc_cur >= 0) then do;
%setEnrCur32(hgc_cur, enr_cur);
end;
else if (enr_cur = -4 and curat_c = 0 and hgc_cur >= 0) then do;
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
end;


*-------------------------------------------------------------------------------;

if ( ((hgc_cur = 10 or hgc_cur = 11) and (hvdip_c = 1 or attcol_c = 1)) or
(dip_cur = 2 and hgc_cur < 12) or
(hgc_cur = -4 and (dip_cur = 1 or dip_cur = 3))) then do;
hgc_cur=12;
if (enr_cur > 0) then
enr_cur = 5 - enr_cur;
else if (curat_c = 1 or (dleyr_ca = lastYr and dlemo_ca >= 5))then
enr_cur = 3;
else
enr_cur = 4;
end;
else if (hgc_cur < 0 and dip_cur = -3) then do;
hgc_cur=-3; enr_cur=-3;
end;

*-------------------------------------------------------------------------------;

if ( (hgc_cur > 20) or
(hgc_cur > hgc_dli + 3 & hgc_dli > 0 & dip_cur ~= 2 & dip_cur ~= 3) or
(hgc_cur > 0 & hgc_dli - 1 > hgc_cur) or
(hgc_cur = 11 & hgc_dli = 12 )) then do;
hgc_cur=-3;
enr_cur=-3;
end;

*-------------------------------------------------------------------------------;

tru=0; * true: 0 - does not have HS diploma (ever), 1 does have a HS diploma 

if (hgc_cur = -3 and enr_cur = -4) then enr_cur=-3;

do i = 1 to dim(dipA);
if (dipA(i) > 1) then do;
tru=1;
if (hgc_cur < 12) then hgc_cur=12; * has HS diploma => has HGC >= 12;
if (enr_cur = 1 or enr_cur < 0) then enr_cur=4; 
leave; 
end;
end;

*-------------------------------------------------------------------------------;

if (flag04 = 0) then do;
hgc_cur=-5; enr_cur=-5;
hgcRev_cur=-5; enrrev_cur=-5;
end;

if (flag04 = 1) then do;
if (hgc_cur = -4) then hgc_cur=-3;
if (enr_cur = -4) then enr_cur=-3;
end;


* ==============================================================================;
* ;
* Create revised variables ;
* ;
* ==============================================================================;
/* 
The revised variables take into account more accurately past reports of HGC to 
eliminate regressive changes in HGC (for instance, preventing someone who has 
previously reported completing 18 years of schooling, and is now working on an 
undergraduate level in some area from being coded lower than 18) */

/* maxGrd - the highest hgc value ever computed */
maxGrd=hgc_cur;
do i = 1 to dim(hgcA);
if (weightA(i) > 0 & hgcA(i) > maxGrd) then
maxGrd = hgcA(i);
end;

if (hgc_cur = -5) then maxGrd = -5;

hgcRev_cur = maxGrd;
enrRev_cur = enr_cur;


run;

HIGHEST GRADE COMPLETED and ENROLLMENT STATUS as of May 1, 2006

* Calculate date last enrolled;

array myIn (*)
jan04_in feb04_in mar04_in apr04_in may04_in jun04_in jul04_in aug04_in sep04_in oct04_in nov04_in dec04_in
jan05_in feb05_in mar05_in apr05_in may05_in jun05_in jul05_in aug05_in sep05_in oct05_in nov05_in dec05_in
jan06_in feb06_in mar06_in apr06_in may06_in jun06_in jul06_in aug06_in sep06_in oct06_in nov06_in dec06_in
jan07_in feb07_in mar07_in apr07_in may07_in jun07_in jul07_in aug07_in sep07_in oct07_in nov07_in dec07_in;

* Get the index of the last year+month when enrolled;
maxI = 0;
do i = dim(myIn) to 1 by -1; *If SAS array 0 based indexes this would be simpler;
if myIn(i) = 1 then do; maxI = i; leave; end;
end;

* Transform maximal myIn index into the corresponding year and month;
if (maxI ~= 0) then do;
dleMo_ca = mod(maxI-1,12)+1;
dleYr_ca = 2004 + floor((maxI-1)/12); * like div: = 2002 + (maxI-1) div 12 ;
end;
else if (curat_c = 1) then do;
dleMo_ca=q_1c_ms;
dleYr_ca=2006;
end;
else do;
dleMo_ca = -4;
dleYr_ca = -4;
end;

proc sort; by norcid;

data oldin;
infile 'hgc/hgc_oldin06_fixed.dat' lrecl=2500 dlm=',' missover;
input
norcid
pubid
curat1-curat21 /* CURRENTLY ATTENDING OR ENROLLED IN SCHOOL*/
dip1-dip21 /* WHICH DOES R HAVE, A HIGH SCHOOL DIPLOMA OR A GED?*/
dlemo1-dlemo21 /* MONTH LAST IN SCHOOL (NOT ENROLLED)*/ /*WHEN R WAS LAST ENROLLED IN REGULAR SCHOOL--WHAT WAS THE MONTH*/
dleyr1-dleyr21 /* YEAR LAST IN SCHOOL (NOT ENROLLED)*/
grade1-grade21 /* GRADE ATTENDING*/
hga1-hga21 /* HIGHEST GRADE ATTENDED*/
hgcs1-hgcs21 /* HIGHEST GRADE COMPLETED*/
hgc1-hgc21 /* CREATED HGC AS OF 05/01/SURVEY YEAR REVISED VERSION*/
hgcu1-hgcu21 /* CREATED HGC AS OF 05/01/SURVEY YEAR UNREVISED VERSION*/
intmo1-intmo21 /* INTERVIEW DATE IN MONTHS*/
weight1-weight21; /* SAMPLING WEIGHT*/

proc sort; by norcid;
proc contents;

*==========================================================================================;
* ;
* Merge IdxWalk & NewIn & OldIn into Merged, and prepare the variables
* ;
*==========================================================================================;

data MERGED;

*------------------------------------------------------------------------------------------;
* Merge: IdxWalk & NewIn & OldIn -> Merged;

merge idxwalk newin2 oldin; by norcid;

*------------------------------------------------------------------------------------------;
* Replace missing values of asli_cur & flag06;

if (asli_cur=.) then asli_cur=-4;
if (flag06=.) then flag06=0;

*------------------------------------------------------------------------------------------;
* Create variables for the current year and the last interview;

hgc_dli=hgc21; *highest grade completed since the date of the last interview;
curantYr=2006; *current ?? year;
lastYr=2004; *last year;

*------------------------------------------------------------------------------------------;
* Make dates reported in 1993 and prior years dleYr Y2K-compliant (e.g. 74 -> 1974);

array dleYr (*) dleyr1 - dleyr15;
array weight (*) weight1 - weight15;

do i = 1 to dim(dleYr);
if (weight(i) > 0 and 0 < dleYr(i) < 100)
then dleYr(i) = dleYr(i) + 1900;
end;

proc sort; by norcid;

/*proc freq; tables dlemo17 dleyr17 dlemo18 dleyr18 dlemo19 dleyr19 dlemo20 dleyr20 dlemo_ca dleyr_ca;*/
/*title 'dle';*/

*===============================================================================;
* ;
* Create Highest Grade Completed and Enrollment Status as of 5-1-2006 ;
* ;
*===============================================================================;

data main;
set Merged (drop= i);

*-------------------------------------------------------------------------------;
* Create all the necessary arrays;

array weightA (*) weight1 - weight21;
array intMoA (*) intMo1 - intMo21;
array dleMoA (*) dleMo1 - dleMo21;
array dleYrA (*) dleYr1 - dleYr21;
array curAtA (*) curAt1 - curAt21;
array hgcSA (*) hgcs1 - hgcs21;
array hgcA (*) hgc1 - hgc21;
array dipA (*) dip1 - dip21;

array intYrA (21) _TEMPORARY_ (1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 /* Interview years */
1990 1991 1992 1993 1994 1996 1998 2000 2002 2004);

hgc_cur=-4; *current highest grade completed;
enr_cur=-4; *current enrollment status;

*-------------------------------------------------------------------------------;
* Set HGC(i) and HGCS(i) to -5 if Weight = 0 ;

do i = 2 to dim(hgcA);
if (weightA(i) = 0) then do;
hgcA(i) = -5;
hgcsA(i) = -5;
end;
end;

*-------------------------------------------------------------------------------;
* Sometimes (?), set hgc_cur to hgcs(i) or hgc(i);

do i = dim(hgcA) to 1 by -1;
if (asli_cur = 0 and /* did not attended school since last interview */
(hvdip_c = -4 or hvdip_c = 0) and /* does not have HS diploma */
flag06 = 1) then do; /* ! Originally was a loop in SPSS */

if (hgc_cur = -4 and weightA(i) > 0) then do; /* Highest Grade completed current */
if ( IntMoA(i) >= 5 and /* Interviewed in May+ */
(CurAtA(i) = 1 or (DLEMoA(i) >= 5 and DLEYrA(i) = IntYrA(i))) and /* Currently in school or was in school after May */
HgcSA(i) > HgcA(i) )
then hgc_cur = HgcSA(i);
else hgc_cur = HgcA(i);
end;
end;
end;

*-------------------------------------------------------------------------------;

if (hgc_cur >= 12)
then enr_cur = 4;
else if (hgc_cur >= 0)
then enr_cur = 1;

*-------------------------------------------------------------------------------;
* Set hgc_cur & enr_cur based on asli_cur, hgcs_cur, hga_cur, grade_c;

%Macro setEnrCur32(aHGC_Cur, aENR_Cur);
do; if (&aHGC_Cur >= 12)
then &aEnr_Cur = 3;
else &aEnr_Cur = 2;
end;
%MEnd;

%Macro setEnrCur41(aHGC_Cur, aENR_Cur);
do; if (&aHGC_Cur >= 12)
then &aEnr_Cur = 4;
else &aEnr_Cur = 1;
end;
%MEnd;

if (asli_cur = 1 and flag06 = 1) then do;
if (hgcs_cur <= 0) then do;
if (curat_c = 1 and grade_c >= 1) then do;
hgc_cur=(grade_c - 1);
%setEnrCur32(hgc_cur, enr_cur);
end;
else if (curat_c = 0 and hga_cur >= 1) then do;
if (dleyr_ca < lastyr or dlemo_ca < 5) then do;
hgc_cur=hga_cur;
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
else do;
hgc_cur=(hga_cur - 1);
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
else if ((hgcs_cur = hga_cur or hgcs_cur = grade_c)) then do;
if ((dleyr_ca = curantyr and dlemo_ca >= 5) or (intmo_c >= 5 and curat_c = 1)) then do;
hgc_cur=(hgcs_cur - 1);
%setEnrCur32(hgc_cur, enr_cur);
end;
else do;
hgc_cur=hgcs_cur;
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
else if ((hgcs_cur = (hga_cur-1)) or
(hgcs_cur = (grade_c-1)) or
(hgcs_cur < hga_cur and 0 < hga_cur < 20) or
(hgcs_cur < grade_c and 0 < grade_c < 20)) then do;
hgc_cur=hgcs_cur;
if (enr_cur = -4 and curat_c = 1 and hgc_cur >= 0) then do;
%setEnrCur32(hgc_cur, enr_cur);
end;
else if (enr_cur = -4 and curat_c = 0 and hgc_cur >= 0) then do;
%setEnrCur41(hgc_cur, enr_cur);
end;
end;
end;

*-------------------------------------------------------------------------------;

if ( ((hgc_cur = 10 or hgc_cur = 11) and (hvdip_c = 1 or attcol_c = 1)) or
(dip_cur = 2 and hgc_cur < 12) or
(hgc_cur = -4 and (dip_cur = 1 or dip_cur = 3))) then do;
hgc_cur=12;
if (enr_cur > 0) then
enr_cur = 5 - enr_cur;
else if (curat_c = 1 or (dleyr_ca = lastYr and dlemo_ca >= 5))then
enr_cur = 3;
else
enr_cur = 4;
end;
else if (hgc_cur < 0 and dip_cur = -3) then do;
hgc_cur=-3; enr_cur=-3;
end;

*-------------------------------------------------------------------------------;

if ( (hgc_cur > 20) or
(hgc_cur > hgc_dli + 3 & hgc_dli > 0 & dip_cur ~= 2 & dip_cur ~= 3) or
(hgc_cur > 0 & hgc_dli - 1 > hgc_cur) or
(hgc_cur = 11 & hgc_dli = 12 )) then do;
hgc_cur=-3;
enr_cur=-3;
end;

*-------------------------------------------------------------------------------;

tru=0; * true: 0 - does not have HS diploma (ever), 1 does have a HS diploma

if (hgc_cur = -3 and enr_cur = -4) then enr_cur=-3;

do i = 1 to dim(dipA);
if (dipA(i) > 1) then do;
tru=1;
if (hgc_cur < 12) then hgc_cur=12; * has HS diploma => has HGC >= 12;
if (enr_cur = 1 or enr_cur < 0) then enr_cur=4;
leave;
end;
end;

*-------------------------------------------------------------------------------;

if (flag06 = 0) then do;
hgc_cur=-5; enr_cur=-5;
hgcRev_cur=-5; enrrev_cur=-5;
end;

if (flag06 = 1) then do;
if (hgc_cur = -4) then hgc_cur=-3;
if (enr_cur = -4) then enr_cur=-3;
end;

* ==============================================================================;
* ;
* Create revised variables ;
* ;
* ==============================================================================;
/*
The revised variables take into account more accurately past reports of HGC to
eliminate regressive changes in HGC (for instance, preventing someone who has
previously reported completing 18 years of schooling, and is now working on an
undergraduate level in some area from being coded lower than 18) */

/* maxGrd - the highest hgc value ever computed */
maxGrd=hgc_cur;
do i = 1 to dim(hgcA);
if (weightA(i) > 0 & hgcA(i) > maxGrd) then
maxGrd = hgcA(i);
end;

if (hgc_cur = -5) then maxGrd = -5;

hgcRev_cur = maxGrd;
enrRev_cur = enr_cur;

 

HIGHEST GRADE COMPLETED AS OF MAY 1, 2008

* Calculate date last enrolled;

 
array myIn (*)
jan06_in feb06_in mar06_in apr06_in may06_in jun06_in jul06_in aug06_in sep06_in oct06_in nov06_in dec06_in
jan07_in feb07_in mar07_in apr07_in may07_in jun07_in jul07_in aug07_in sep07_in oct07_in nov07_in dec07_in
jan08_in feb08_in mar08_in apr08_in may08_in jun08_in jul08_in aug08_in sep08_in oct08_in nov08_in dec08_in;

* Get the index of the last year+month when enrolled;
maxI = 0;
do i = dim(myIn) to 1 by -1;                  *If SAS array 0 based indexes this would be simpler;
    if myIn(i) = 1 then do; maxI = i; leave; end;
end;

* Transform maximal myIn index into the corresponding year and month;
if (maxI ~= 0) then do;
    dleMo_ca = mod(maxI-1,12)+1;
    dleYr_ca = 2006 + floor((maxI-1)/12);      * like div: = 2002 + (maxI-1) div 12 ;
end;

else if (curat_c = 1) then do;                 * taken from the code in hands_edits_hgc_vars file;
    dleMo_ca=q_1c_ms;
    dleYr_ca=2008;
end;

else do;
    dleMo_ca = -4;
    dleYr_ca = -4;
end;

proc sort; by norcid;
data oldin;
infile  'hgc06_oldin.dat' lrecl=5000 dlm=' ' dsd missover;
input
  norcid
  pubid
  curat1-curat22     /* CURRENTLY ATTENDING OR ENROLLED IN SCHOOL*/
  dip1-dip22         /* WHICH DOES R HAVE, A HIGH SCHOOL DIPLOMA OR A GED?*/
  dlemo1-dlemo22     /* MONTH LAST IN SCHOOL (NOT ENROLLED)*/ /*WHEN R WAS LAST ENROLLED IN REGULAR SCHOOL--WHAT WAS THE MONTH*/
  dleyr1-dleyr22     /* YEAR LAST IN SCHOOL (NOT ENROLLED)*/
  grade1-grade22     /* GRADE ATTENDING*/
  hga1-hga22         /* HIGHEST GRADE ATTENDED*/
  hgcs1-hgcs22       /* HIGHEST GRADE COMPLETED*
  hgc1-hgc22         /* CREATED HGC AS OF 05/01/SURVEY YEAR  REVISED VERSION*/
  hgcu1-hgcu22       /* CREATED HGC AS OF 05/01/SURVEY YEAR  UNREVISED VERSION*/
  intmo1-intmo22     /* INTERVIEW DATE IN MONTHS*/
  weight1-weight22;  /* SAMPLING WEIGHT*/
run;

proc sort;by norcid;

*========================================================================;

*                                                                                          ;

* Merge IdxWalk & NewIn & OldIn into Merged, and prepare the variables
*                                                                                          ;

*========================================================================;
 
data MERGED;

*------------------------------------------------------------------------------------------;

* Merge: IdxWalk & NewIn & OldIn -> Merged;

merge idxwalk newin2 oldin; by norcid;

*------------------------------------------------------------------------------------------;
* Replace missing values of asli_cur & flag08;

if (asli_cur=.) then asli_cur=-4;

if (flag08=.) then flag08=0;

*------------------------------------------------------------------------------------------;

* Create variables for the current year and the last interview;

hgc_dli=hgc22;   *highest grade completed since the date of the last interview;

curantYr=2008;   *current ?? year;

lastYr=2006;     *last year;

*------------------------------------------------------------------------------------------;

* Make dates reported in 1993 and prior years dleYr Y2K-compliant (e.g. 74 -> 1974);

array dleYr (*) dleyr1 - dleyr15;
array weight (*) weight1 - weight15;

do i = 1 to dim(dleYr);
    if (weight(i) > 0 and 0 < dleYr(i) < 100)
        then dleYr(i) = dleYr(i) + 1900;
end;

proc sort; by norcid;
 
*==========================================================================;
*                                                                               ;
* Create Highest Grade Completed and Enrollment Status as of 5-1-2008           ;
*                                                                               ;
*==========================================================================;

data main;
set Merged (drop= i);
 
*-------------------------------------------------------------------------------;
* Create all the necessary arrays;
 
array weightA  (*) weight1 - weight22;
array intMoA   (*) intMo1  - intMo22;
array dleMoA   (*) dleMo1  - dleMo22;
array dleYrA   (*) dleYr1  - dleYr22;

array curAtA   (*) curAt1  - curAt22;

array hgcSA    (*) hgcs1   - hgcs22;

array hgcA     (*) hgc1    - hgc22;

array dipA     (*) dip1    - dip22;

array intYrA (22) _TEMPORARY_ (1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989    

/* Interview years */

                  1990 1991 1992 1993 1994 1996 1998 2000 2002 2004 2006);

hgc_cur=-4;             *current highest grade completed;
enr_cur=-4;             *current enrollment status;

*-------------------------------------------------------------------------------;

* Set HGC(i) and HGCS(i) to -5 if Weight = 0 ;
do i = 2 to dim(hgcA);
    if (weightA(i) = 0) then do;
             hgcA(i) = -5;
             hgcsA(i) = -5;
        end;
end;
 
*-------------------------------------------------------------------------------;

* Set hgc_cur to hgcs(i) or hgc(i);
 
do i = dim(hgcA) to 1 by -1;
    if  (asli_cur = 0 and                    /* did not attend school since last interview */
        (hvdip_c = -4 or hvdip_c = 0) and    /* does not have HS diploma */
        flag08 = 1) then do;                 /* ! Originally was a loop in SPSS */

        if (hgc_cur = -4 and weightA(i) > 0) then do; /* Highest Grade completed current */
            if ( IntMoA(i) >= 5 and                   /* Interviewed in May+ */
                (CurAtA(i) = 1 or (DLEMoA(i) >= 5 and DLEYrA(i) = IntYrA(i))) and /* Currently in school or was in school after May */
                 HgcSA(i) > HgcA(i) )
                then hgc_cur = HgcSA(i);  /*Highest grade completed*/
                else hgc_cur = HgcA(i);                     /* Created HGC as of 05/01 survey year revised version*/
        end;
        /*if ((flag06 = 0) and (hgc_cur ~= -4) and (Weight(i) > 0)) then leave; - works without it*/
    end;
end;

*-------------------------------------------------------------------------------;

* Set enr_cur;
if (hgc_cur >= 12)
    then enr_cur = 4;
else if (hgc_cur >= 0)
    then enr_cur = 1;

*-------------------------------------------------------------------------------;
* Set hgc_cur & enr_cur based on asli_cur, hgcs_cur, hga_cur, grade_c, ...;

%Macro setEnrCur32(aHGC_Cur, aENR_Cur);
    do; if (&aHGC_Cur >= 12)
        then &aEnr_Cur = 3;
        else &aEnr_Cur = 2;
    end;
%MEnd;
%Macro setEnrCur41(aHGC_Cur, aENR_Cur);
    do; if (&aHGC_Cur >= 12)
        then &aEnr_Cur = 4;
        else &aEnr_Cur = 1;
    end;
%MEnd;

if (asli_cur = 1 and flag08 = 1) then do;
    if (hgcs_cur <= 0)  then do;
        if (curat_c = 1 and grade_c >= 1) then do;
            hgc_cur=(grade_c - 1);
            %setEnrCur32(hgc_cur, enr_cur);
        end;
        else if (curat_c = 0 and hga_cur >= 1) then do;
            if (dleyr_ca < lastyr or dlemo_ca < 5) then do;
                hgc_cur=hga_cur;
                %setEnrCur41(hgc_cur, enr_cur);
            end;
        end;
        else do;
            hgc_cur=(hga_cur - 1);
            %setEnrCur41(hgc_cur, enr_cur);
        end;
    end;
    else if ((hgcs_cur = hga_cur or hgcs_cur = grade_c))  then do;
        if ((dleyr_ca = curantyr and dlemo_ca >= 5) or (intmo_c >= 5 and curat_c = 1))  then do;
            hgc_cur=(hgcs_cur - 1);
            %setEnrCur32(hgc_cur, enr_cur);
        end;
        else do;
            hgc_cur=hgcs_cur;
            %setEnrCur41(hgc_cur, enr_cur);
        end;
    end;
    else if ((hgcs_cur = (hga_cur-1)) or
             (hgcs_cur = (grade_c-1)) or
             (hgcs_cur < hga_cur and 0 < hga_cur < 20) or
             (hgcs_cur < grade_c and 0 < grade_c < 20)) then do;
        hgc_cur=hgcs_cur;
        if (enr_cur = -4 and curat_c = 1 and hgc_cur >= 0) then do;
            %setEnrCur32(hgc_cur, enr_cur);
        end;
        else if (enr_cur = -4 and curat_c = 0 and hgc_cur >= 0) then do;
            %setEnrCur41(hgc_cur, enr_cur);
        end;
    end;
end;

*-------------------------------------------------------------------------------;
if ( ((hgc_cur = 10 or hgc_cur = 11) and (hvdip_c = 1 or attcol_c = 1)) or
     (dip_cur = 2 and hgc_cur < 12) or
     (hgc_cur = -4 and (dip_cur = 1 or dip_cur = 3))) then do;
    hgc_cur=12;
    if (enr_cur > 0) then
        enr_cur = 5 - enr_cur;
    else if (curat_c = 1 or (dleyr_ca = lastYr and dlemo_ca >= 5))then
        enr_cur = 3;
    else
        enr_cur = 4;
end;

else if (hgc_cur < 0 and dip_cur = -3) then do;
    hgc_cur=-3; enr_cur=-3;
end;

*-------------------------------------------------------------------------------;

if ( (hgc_cur > 20) or
    (hgc_cur > hgc_dli + 3 & hgc_dli > 0 & dip_cur ~= 2 & dip_cur ~= 3) or
     (hgc_cur > 0  & hgc_dli - 1 > hgc_cur) or
     (hgc_cur = 11 & hgc_dli = 12 )) then do;
    hgc_cur=-3;
    enr_cur=-3;
end;

*-------------------------------------------------------------------------------;

tru=0;          * true: 0 - does not have HS diploma (ever), 1 does have a HS diploma;
if (hgc_cur = -3 and enr_cur = -4) then enr_cur=-3;
do i = 1 to dim(dipA);
    if (dipA(i) > 1) then do;
        tru=1;
        if (hgc_cur < 12) then hgc_cur=12;               * has HS diploma => has HGC >= 12;
        if (enr_cur = 1 or enr_cur < 0) then enr_cur=4;  
        leave;
    end;
end;

*-------------------------------------------------------------------------------;

if (flag08 = 0) then do;
    hgc_cur=-5;  enr_cur=-5;
    hgcRev_cur=-5; enrrev_cur=-5;
end;
if (flag08 = 1) then do;
    if (hgc_cur = -4) then hgc_cur=-3;
    if (enr_cur = -4) then enr_cur=-3;
end;

* =========================================================================;
*                                                                               ;
* Create revised variables                                                      ;
*                                                                               ;
* =========================================================================;

/*

The revised variables take into account more accurately past reports of HGC to
eliminate regressive changes in HGC (for instance, preventing someone who has
previously reported completing 18 years of schooling, and is now working on an
undergraduate level in some area from being coded lower than 18) */

/* maxGrd - the highest hgc value ever computed */

maxGrd=hgc_cur;
do i = 1 to dim(hgcA);
    if (weightA(i) > 0 & hgcA(i) > maxGrd) then
        maxGrd = hgcA(i);
end;

if (hgc_cur = -5) then maxGrd = -5;

hgcRev_cur = maxGrd;
enrRev_cur = enr_cur;

HIGHEST GRADE COMPLETED AS OF MAY 1, 2010

*------------------------------------------------------------------------------------------;

* Calculate date last enrolled;

array myIn (*)
jan08_in feb08_in mar08_in apr08_in may08_in jun08_in jul08_in aug08_in sep08_in oct08_in nov08_in dec08_in
jan09_in feb09_in mar09_in apr09_in may09_in jun09_in jul09_in aug09_in sep09_in oct09_in nov09_in dec09_in
jan10_in feb10_in mar10_in apr10_in may10_in jun10_in jul10_in aug10_in sep10_in oct10_in nov10_in dec10_in;
 

* Get the index of the last year+month when enrolled;
maxI = 0;
do i = dim(myIn) to 1 by -1;                  *If SAS array 0 based indexes this would be simpler;
    if myIn(i) = 1 then do; maxI = i; leave; end;
end;

* Transform maximal myIn index into the corresponding year and month;
if (maxI ~= 0) then do;
    dleMo_ca = mod(maxI-1,12)+1;
    dleYr_ca = 2008 + floor((maxI-1)/12);      * like div: = 2002 + (maxI-1) div 12 ;
end;
else if (curat_c = 1) then do;                 * taken from the code in hands_edits_hgc_vars file;
    dleMo_ca=q_1c_ms;
    dleYr_ca=2010;
end;
else do;
    dleMo_ca = -4;
    dleYr_ca = -4;
end;

proc sort; by norcid;
run;

*Note: The following data file was created separately by running a program named "hgc_oldin08.sas";

data oldin;
infile  'hgc08_oldin.dat' lrecl=5000 missover dlm=' ' dsd TERMSTR=CRLF;
input
  norcid
  pubid
  curat1-curat23     /* CURRENTLY ATTENDING OR ENROLLED IN SCHOOL*/
  dip1-dip23         /* WHICH DOES R HAVE, A HIGH SCHOOL DIPLOMA OR A GED?*/
  dlemo1-dlemo23     /* MONTH LAST IN SCHOOL (NOT ENROLLED)*/ /*WHEN R WAS LAST ENROLLED IN REGULAR SCHOOL--WHAT WAS THE MONTH*/
  dleyr1-dleyr23     /* YEAR LAST IN SCHOOL (NOT ENROLLED)*/
  grade1-grade23     /* GRADE ATTENDING*/
  hga1-hga23         /* HIGHEST GRADE ATTENDED*/
  hgcs1-hgcs23       /* HIGHEST GRADE COMPLETED*/
  hgc1-hgc23         /* CREATED HGC AS OF 05/01/SURVEY YEAR  REVISED VERSION*/
  hgcu1-hgcu23       /* CREATED HGC AS OF 05/01/SURVEY YEAR  UNREVISED VERSION*/
  intmo1-intmo23     /* INTERVIEW DATE IN MONTHS*/
  weight1-weight23;  /* SAMPLING WEIGHT*/

proc sort; by norcid;
proc contents;

*==========================================================================================;
*                                                                                          ;
* Merge IdxWalk & NewIn & OldIn into Merged, and prepare the variables
*                                                                                          ;
*==========================================================================================;

data MERGED;

*------------------------------------------------------------------------------------------;
* Merge: IdxWalk & NewIn & OldIn -> Merged;
merge idxwalk newin2 oldin; by norcid;
*------------------------------------------------------------------------------------------;
* Replace missing values of asli_cur & flag10;

if (asli_cur=.) then asli_cur=-4;
if (flag10=.) then flag10=0;

*------------------------------------------------------------------------------------------;

* Create variables for the current year and the last interview;

hgc_dli=hgc23;   *highest grade completed since the date of the last interview;
curantYr=2010;   *current ?? year;
lastYr=2008;     *last year;
 
*------------------------------------------------------------------------------------------;

* Make dates reported in 1993 and prior years dleYr Y2K-compliant (e.g. 74 -> 1974);
array dleYr  (*) dleyr1 - dleyr15;
array weight (*) weight1 - weight15;
do i = 1 to dim(dleYr);
    if (weight(i) > 0 and 0 < dleYr(i) < 100)
        then dleYr(i) = dleYr(i) + 1900;
end;
proc sort; by norcid;
run;

*===============================================================================;
*                                                                               ;
* Create Highest Grade Completed and Enrollment Status as of 5-1-2010           ;
*                                                                               ;
*===============================================================================;

data main;
set Merged (drop= i);
 
*-------------------------------------------------------------------------------;

* Create all the necessary arrays;

array weightA  (*) weight1 - weight23;
array intMoA   (*) intMo1  - intMo23;
array dleMoA   (*) dleMo1  - dleMo23;
array dleYrA   (*) dleYr1  - dleYr23;
array curAtA   (*) curAt1  - curAt23;
array hgcSA    (*) hgcs1   - hgcs23;
array hgcA     (*) hgc1    - hgc23;
array dipA     (*) dip1    - dip23;
array intYrA (23) _TEMPORARY_ (1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989    /* Interview years */
                  1990 1991 1992 1993 1994 1996 1998 2000 2002 2004 2006 2008);
hgc_cur=-4;             *current highest grade completed;
enr_cur=-4;             *current enrollment status;

*-------------------------------------------------------------------------------;
* Set HGC(i) and HGCS(i) to -5 if Weight = 0 ;

do i = 2 to dim(hgcA);
    if (weightA(i) = 0) then do;
             hgcA(i) = -5;
             hgcsA(i) = -5;
        end;
end;

*-------------------------------------------------------------------------------;

* Sometimes (?), set hgc_cur to hgcs(i) or hgc(i);

do i = dim(hgcA) to 1 by -1;
    if  (asli_cur = 0 and                    /* did not attend school since last interview */
        (hvdip_c = -4 or hvdip_c = 0) and    /* does not have HS diploma */
        flag10 = 1) then do;                 /* ! Originally was a loop in SPSS */
        if (hgc_cur = -4 and weightA(i) > 0) then do; /* Highest Grade completed current */
            if ( IntMoA(i) >= 5 and                   /* Interviewed in May+ */
                (CurAtA(i) = 1 or (DLEMoA(i) >= 5 and DLEYrA(i) = IntYrA(i))) and /* Currently in school or was in school after May */
                 HgcSA(i) > HgcA(i) )
                then hgc_cur = HgcSA(i);     /* Highest grade completed*/
                else hgc_cur = HgcA(i);                    /* Created HGC as of 05/01 survey year revised version*/
        end;

        /*if ((flag06 = 0) and (hgc_cur ~= -4) and (Weight(i) > 0)) then leave; - works without it*/

    end;
end;

*-------------------------------------------------------------------------------;

if (hgc_cur >= 12)
    then enr_cur = 4;
else if (hgc_cur >= 0)
    then enr_cur = 1;

*-------------------------------------------------------------------------------;

%Macro setEnrCur32(aHGC_Cur, aENR_Cur);
    do; if (&aHGC_Cur >= 12)
        then &aEnr_Cur = 3;
        else &aEnr_Cur = 2;
    end;
%MEnd;

%Macro setEnrCur41(aHGC_Cur, aENR_Cur);
    do; if (&aHGC_Cur >= 12)
        then &aEnr_Cur = 4;
        else &aEnr_Cur = 1;
    end;
%MEnd;

if (asli_cur = 1 and flag10 = 1) then do;
    if (hgcs_cur <= 0)  then do;
        if (curat_c = 1 and grade_c >= 1) then do;
            hgc_cur=(grade_c - 1);
            %setEnrCur32(hgc_cur, enr_cur);
        end;

        else if (curat_c = 0 and hga_cur >= 1) then do;
            if (dleyr_ca < lastyr or dlemo_ca < 5) then do;
                hgc_cur=hga_cur;
                %setEnrCur41(hgc_cur, enr_cur);
            end;
        end;
        else do;
            hgc_cur=(hga_cur - 1);
            %setEnrCur41(hgc_cur, enr_cur);
        end;
    end;
    else if ((hgcs_cur = hga_cur or hgcs_cur = grade_c))  then do;
        if ((dleyr_ca = curantyr and dlemo_ca >= 5) or (intmo_c >= 5 and curat_c = 1))  then do;
            hgc_cur=(hgcs_cur - 1);
            %setEnrCur32(hgc_cur, enr_cur);
        end;
        else do;
            hgc_cur=hgcs_cur;
            %setEnrCur41(hgc_cur, enr_cur);
        end;
    end;
    else if ((hgcs_cur = (hga_cur-1)) or
             (hgcs_cur = (grade_c-1)) or
             (hgcs_cur < hga_cur and 0 < hga_cur < 20) or
             (hgcs_cur < grade_c and 0 < grade_c < 20)) then do;
        hgc_cur=hgcs_cur;
        if (enr_cur = -4 and curat_c = 1 and hgc_cur >= 0) then do;
            %setEnrCur32(hgc_cur, enr_cur);
        end;
        else if (enr_cur = -4 and curat_c = 0 and hgc_cur >= 0) then do;
            %setEnrCur41(hgc_cur, enr_cur);
        end;
    end;
end;

*-------------------------------------------------------------------------------;

if ( ((hgc_cur = 10 or hgc_cur = 11) and (hvdip_c = 1 or attcol_c = 1)) or
     (dip_cur = 2 and hgc_cur < 12) or
     (hgc_cur = -4 and (dip_cur = 1 or dip_cur = 3))) then do;
    hgc_cur=12;
    if (enr_cur > 0) then
        enr_cur = 5 - enr_cur;
    else if (curat_c = 1 or (dleyr_ca = lastYr and dlemo_ca >= 5))then
        enr_cur = 3;
    else
        enr_cur = 4;
end;

else if (hgc_cur < 0 and dip_cur = -3) then do;
    hgc_cur=-3; enr_cur=-3;
end;

*-------------------------------------------------------------------------------;

if ( (hgc_cur > 20) or
     (hgc_cur > hgc_dli + 3 & hgc_dli > 0 & dip_cur ~= 2 & dip_cur ~= 3) or
     (hgc_cur > 0  & hgc_dli - 1 > hgc_cur) or
     (hgc_cur = 11 & hgc_dli = 12 )) then do;
    hgc_cur=-3;
    enr_cur=-3;
end;

*-------------------------------------------------------------------------------;

tru=0;          * true: 0 - does not have HS diploma (ever), 1 does have a HS diploma
 
if (hgc_cur = -3 and enr_cur = -4) then enr_cur=-3;
 
do i = 1 to dim(dipA);
    if (dipA(i) > 1) then do;
        tru=1;
        if (hgc_cur < 12) then hgc_cur=12;               * has HS diploma => has HGC >= 12;
        if (enr_cur = 1 or enr_cur < 0) then enr_cur=4;  
        leave;
    end;
end;

*-------------------------------------------------------------------------------;

if (flag10 = 0) then do;
    hgc_cur=-5;  enr_cur=-5;
    hgcRev_cur=-5; enrrev_cur=-5;
end;

if (flag10 = 1) then do;
    if (hgc_cur = -4) then hgc_cur=-3;
    if (enr_cur = -4) then enr_cur=-3;
end;

* ==============================================================================;
*                                                                               ;
* Create revised variables                                                      ;
*                                                                               ;
* ==============================================================================;

/*

The revised variables take into account more accurately past reports of HGC to
eliminate regressive changes in HGC (for instance, preventing someone who has
previously reported completing 18 years of schooling, and is now working on an
undergraduate level in some area from being coded lower than 18) */

/* maxGrd - the highest hgc value ever computed */

maxGrd=hgc_cur;
do i = 1 to dim(hgcA);
    if (weightA(i) > 0 & hgcA(i) > maxGrd) then
        maxGrd = hgcA(i);
end;

if (hgc_cur = -5) then maxGrd = -5;

hgcRev_cur = maxGrd;
enrRev_cur = enr_cur;

HIGHEST GRADE COMPLETED AS OF MAY 1, 2012

HIGHEST GRADE COMPLETED AS OF MAY 1, 2012

* Calculate date last enrolled;

array myIn (*)
jan10_in feb10_in mar10_in apr10_in may10_in jun10_in jul10_in aug10_in sep10_in oct10_in nov10_in dec10_in
jan11_in feb11_in mar11_in apr11_in may11_in jun11_in jul11_in aug11_in sep11_in oct11_in nov11_in dec11_in
jan12_in feb12_in mar12_in apr12_in may12_in jun12_in jul12_in aug12_in sep12_in oct12_in nov12_in dec12_in
jan13_in feb13_in mar13_in apr13_in may13_in jun13_in;

* Get the index of the last year+month when enrolled;
maxI = 0;
do i = dim(myIn) to 1 by -1; *If SAS array 0 based indexes this would be simpler;
if myIn(i) = 1 then do; maxI = i; leave; end;
end;

* Transform maximal myIn index into the corresponding year and month;
if (maxI ~= 0) then do;
dleMo_ca = mod(maxI-1,12)+1;
dleYr_ca = 2010 + floor((maxI-1)/12); * like div: = 2002 + (maxI-1) div 12 ;
end;
else if (curat_c = 1) then do;
dleMo_ca=q_1c_ms;
dleYr_ca=q_1c_yr;
end;
else do;
dleMo_ca = -4;
dleYr_ca = -4;
end;

proc sort; by norcid;
run;

The following data file was created separately by running a program named "hgc_oldin10.sas";

data oldin;
set schR25.hgc_oldin10;

* curat1-curat24 /* CURRENTLY ATTENDING OR ENROLLED IN SCHOOL*/
dip1-dip24 /* WHICH DOES R HAVE, A HIGH SCHOOL DIPLOMA OR A GED?*/
dlemo1-dlemo24 /* MONTH LAST IN SCHOOL (NOT ENROLLED)*/ /*WHEN R WAS LAST ENROLLED IN REGULAR SCHOOL--WHAT WAS THE MONTH*/
dleyr1-dleyr24 /* YEAR LAST IN SCHOOL (NOT ENROLLED)*/
grade1-grade24 /* GRADE ATTENDING*/
hga1-hga24 /* HIGHEST GRADE ATTENDED*/
hgcs1-hgcs24 /* HIGHEST GRADE COMPLETED*/
hgc1-hgc24 /* CREATED HGC AS OF 05/01/SURVEY YEAR REVISED VERSION*/
hgcu1-hgcu24 /* CREATED HGC AS OF 05/01/SURVEY YEAR UNREVISED VERSION*/
intmo1-intmo24 /* INTERVIEW DATE IN MONTHS*/
weight1-weight24; /* SAMPLING WEIGHT*/

proc sort; by norcid;
proc contents;

*==========================================================================================;
* ;
* Merge NewIn & OldIn into Merged, and prepare the variables ;
* ;
*==========================================================================================;

data MERGED;
merge newin oldin; by norcid;

*------------------------------------------------------------------------------------------;
* Replace missing values of asli_cur & flag12;

if (asli_cur=.) then asli_cur=-4;
if (flag12=.) then flag12=0;

*------------------------------------------------------------------------------------------;
* Create variables for the current year and the last interview;

hgc_dli=hgc10; *highest grade completed last round;
curantYr=2012; *current ?? year;
lastYr=2010; *last year;

*------------------------------------------------------------------------------------------;
* Make dates reported in 1993 and prior years dleYr Y2K-compliant (e.g. 74 -> 1974);

array dleYr (*) dleyr79 - dleyr93;
array weight (*) weight79 - weight93;

do i = 1 to dim(dleYr);
if (weight(i) > 0 and 0 < dleYr(i) < 100)
then dleYr(i) = dleYr(i) + 1900;
end;

*===============================================================================;
* ;
* Create Highest Grade Completed as of 5-1-2012 ;
* ;
*===============================================================================;

*-------------------------------------------------------------------------------;
* Create all the necessary arrays;

array weightA (*) weight79 - weight94 weight96 weight98 weight00 weight02 weight04 weight06 weight08 weight10;
array intMoA (*) intMo79 - intMo94 intMo96 intMo98 intMo00 intMo02 intMo04 intMo06 intMo08 intMo10;
array dleMoA (*) dleMo79 - dleMo94 dleMo96 dleMo98 dleMo00 dleMo02 dleMo04 dleMo06 dleMo08 dleMo10;
array dleYrA (*) dleYr79 - dleYr94 dleYr96 dleYr98 dleYr00 dleYr02 dleYr04 dleYr06 dleYr08 dleYr10;
array curAtA (*) curAt79 - curAt94 curAt96 curAt98 curAt00 curAt02 curAt04 curAt06 curAt08 curAt10;
array hgcSA (*) hgcS79 - hgcS94 hgcS96 hgcS98 hgcS00 hgcS02 hgcS04 hgcS06 hgcS08 hgcS10;
array hgcA (*) hgc79 - hgc94 hgc96 hgc98 hgc00 hgc02 hgc04 hgc06 hgc08 hgc10;
array dipA (*) dip79 - dip94 dip96 dip98 dip00 dip02 dip04 dip06 dip08 dip10;
array intYrA (*) intYr79 - intYr94 intYr96 intYr98 intYr00 intYr02 intYr04 intYr06 intYr08 intYr10;

do i=1 to 15;
intYrA(i) = 1978+i;
end;
    
array mayA (24) _TEMPORARY_ (5 17 29 41 53 65 77 89 101 113 125 137 149 161 173 185 209 233 257 281 305 329 353 377);
array intA (*) int79 - int94 int96 int98 int00 int02 int04 int06 int08 int10;
array dleA (*) dle79 - dle94 dle96 dle98 dle00 dle02 dle04 dle06 dle08 dle10;

hgc_cur=-4; *current highest grade completed;

do i=1 to dim (mayA);
if intMoA(i)>0 & intYrA(i)>0 then intA(i)=12*(intYrA(i)-1979)+intMoA(i);
else if weightA(i)=0 then intA(i)=-5;
if dleMoA(i)>0 & dleYrA(i)>0 then dleA(i)=12*(dleYrA(i)-1979)+dleMoA(i);
else if weightA(i)=0 then dleA(i)=-5;
else if -4<dleMoA(i)<0 or -4<dleYrA(i)<0 then dleA(i)=-3;
else dleA(i)=-4;
end;
*-------------------------------------------------------------------------------;
* Set HGC(i) and HGCS(i) to -5 if Weight = 0 ;

do i = 2 to dim(hgcA);
if (weightA(i) = 0) then do;
hgcA(i) = -5;
hgcsA(i) = -5;
end;
end;

*-------------------------------------------------------------------------------;
* Sometimes, set hgc_cur to hgcs(i) or hgc(i);

*do i = dim(hgcA) to 1 by -1;
if (asli_cur = 0 and /* did not attend school since last interview */
flag12 = 1) then do i = dim(hgcA) to 1 by -1;

if (hgc_cur = -4 and weightA(i) > 0) then do; /* Highest Grade completed current */
*if ( IntMoA(i) >= 5 and /* Interviewed in May+ */
(CurAtA(i) = 1 or (DLEMoA(i) >= 5 and DLEYrA(i) = IntYrA(i))) and /* Currently in school or was in school after May */
HgcSA(i) > HgcA(i) )
then hgc_cur = HgcSA(i);    /* Highest grade completed*/
            if ( IntA(i) >= mayA(i) and /* Interviewed in May+ */
(CurAtA(i) = 1 or DLEA(i) >= mayA(i)) and /* Currently in school or was in school after May */
HgcSA(i) > HgcA(i) )
then hgc_cur = HgcSA(i);    /* Highest grade completed*/
else hgc_cur = HgcA(i);        /* Created HGC as of 05/01 survey year revised version*/
end;
end;

*-------------------------------------------------------------------------------;

if (asli_cur = 1 and flag12 = 1) then do;
if (hgcs_cur <= 0) then do;
if (curat_c = 1 and grade_c >= 1) then
hgc_cur=(grade_c - 1);
else if (curat_c = 0 and hga_cur >= 1) then do;
*if (dleyr_ca < lastyr or dlemo_ca < 5) then do;
            if (dleyr_ca < curantYr) or (dleyr_ca=curantYr and dlemo_ca < 5) then
hgc_cur=hga_cur;
end;
*else hgc_cur=(hga_cur - 1);
        else if hga_cur>0 then hgc_cur=(hga_cur - 1);
end;
else if ((hgcs_cur = hga_cur or hgcs_cur = grade_c)) then do;
*if ((dleyr_ca = curantyr and dlemo_ca >= 5) or (intmo_c >= 5 and curat_c = 1)) then do;
if ((dleyr_ca>curantyr) or (dleyr_ca = curantyr and dlemo_ca >= 5) or (curat_c = 1)) then
hgc_cur=(hgcs_cur - 1);
else hgc_cur=hgcs_cur;
end;
else if ((hgcs_cur = (hga_cur-1)) or
(hgcs_cur = (grade_c-1)) or
/*(hgcs_cur < hga_cur and 0 < hga_cur < 20) or
(hgcs_cur < grade_c and 0 < grade_c < 20)) then*/
             (hgcs_cur < hga_cur and 0 < hga_cur <= 20) or
(hgcs_cur < grade_c and 0 < grade_c <= 20)) then
hgc_cur=hgcs_cur;
end;

*-------------------------------------------------------------------------------;

if ( ((hgc_cur = 10 or hgc_cur = 11) and (hvdip_c = 1 or attcol_c = 1)) or
     (dip_cur>=1 and hgc_cur < 12) or
(hgc_cur = -4 and (dip_cur = 1 or dip_cur = 3))) then
hgc_cur=12;
else if (hgc_cur < 0 and dip_cur = -3) then
hgc_cur=-3;
*-------------------------------------------------------------------------------;

if ( (hgc_cur > 20) or
(hgc_cur > hgc_dli + 3 & hgc_dli > 0 & dip_cur ~= 2 & dip_cur ~= 3) or
(hgc_cur = 11 & hgc_dli = 12 )) then
     hgc_cur=-3;

*-------------------------------------------------------------------------------;

tru=0; * true: 0 - does not have HS diploma (ever), 1 does have a HS diploma;

do i = 1 to dim(dipA);
*if (dipA(i) > 1) then do;
    if (dipA(i) > =1) then do; /* XA changed for R25 */
tru=1;
if (hgc_cur < 12) then hgc_cur=12; * has HS diploma => has HGC >= 12;
leave;
end;
end;

*-------------------------------------------------------------------------------;

if (flag12 = 0) then do;
hgc_cur=-5;
hgcRev_cur=-5;
end;

if (flag12 = 1) then do;
if (hgc_cur = -4) then hgc_cur=-3;
end;

* ==============================================================================;
* ;
* Create revised variables ;
* ;
* ==============================================================================;
/*
The revised variables take into account more accurately past reports of HGC to
eliminate regressive changes in HGC (for instance, preventing someone who has
previously reported completing 18 years of schooling, and is now working on an
undergraduate level in some area from being coded lower than 18) */

/* maxGrd - the highest hgc value ever computed */

maxGrd=hgc_cur;
do i = 1 to dim(hgcA);
if (weightA(i) > 0 & hgcA(i) > maxGrd) then
maxGrd = hgcA(i);
end;

if (hgc_cur = -5) then maxGrd = -5;

hgcRev_cur = maxGrd;