/*INCARCERATION HISTORY ARRAY: INCARC_STATUS_year.month*/ /*codes and their definitions are as follows: -4 Assigned if R is younger than 12 years old in this month or has not been interviewed about this month 0 Assigned if R was not incarcerated this month and previously never incarcerated 1 Indicates R was incarcerated during all or some portion of this month 99 Indication R was not incarcerated this month but has previously been incarcerated Creates: INCARC_STATUS INCARC_FIRST INCARC_TOTNUM INCARC_AGE_FIRST INCARC_LENGTH_FIRST INCARC_LENGTH_LONGEST INCARC_TOTMONTHS INCARC_CURRENT*/ /* YSAQ_438A C438A * Incarc at prior interview? YSAQ_438B C438B_Y * YEAR RELEASED FROM INCAR (incarc at DLI) YSAQ_438C C438C_M * Month released (incarc at DLI) YSAQ_494_01 C4941 * sentenced (arrest1) YSAQ_494_02 C4942 * sentenced (arrest2) YSAQ_494_03 C4943 * sentenced (arrest3) YSAQ_494_04 C4944 * sentenced (arrest4) YSAQ_495_01 C495M1 * month start (incar1) YSAQ_495_02 C495M2 * month start (incar2) YSAQ_495_03 C495M3 * month start (incar3) YSAQ_496_01_Y C496Y1 * year start (incar1) YSAQ_496_02_Y C496Y2 * year start (incar2) YSAQ_496_03_Y C496Y3 * year start (incar3) YSAQ_497_01 C4971 * currently incarc? (incar1) YSAQ_497_02 C4972 * currently incarc? (incar2) YSAQ_497_03 C4973 * currently incarc? (incar3) YSAQ_498_01 C498M1 * month released (incar1) YSAQ_498_02 C498M2 * month released (incar2) YSAQ_498_03 C498M3 * month released (incar3) YSAQ_499_01_Y C499Y1 * year released (incar1) YSAQ_499_02_Y C499Y2 * year released (incar2) YSAQ_499_03_Y C499Y3 * year released (incar3) SYMBOL_KEY_BDATE_D bdate_d SYMBOL_KEY_BDATE_M bdate_m SYMBOL_KEY_BDATE_Y bdate_y YSAQ_INCARCERATED INCAR_chk * R is incarcerated (if in 1,2) (n=94, 10 selfadmin(1), 84 interviewer admin (2) YSAQ_DWELLINGCHECK DWELL_chk * is R incarcerated (1) YSAQ_PRISONCHECK PRISON_CHK *audible prison interview (n=84) YHHI_4400 HHI_4400 (7=In Jail) YHHI_4505 HHI_4505 (duration in temporary dwelling) */ options pagesize=54 linesize=93 nocenter nodate; libname r21incar 'J:\R21 Incarceration'; options symbolgen; OPTIONS VALIDVARNAME=ANY; %macro c_month ( mo , ye, cm); if &mo.>0 & &ye.>0 then &cm=(&ye.-1980)*12+&mo.; if &Ye =-5 then &cm=-5; %mend c_month ; %macro c_iym(mo, ye, iym, dlidate); &iym.=-4; if &mo.>0 & &ye.>0 then &iym=&ye.*100+&mo.; if &ye.=-5 then &iym.=&dlidate.; %mend c_iym ; data one; set r21incar.R21incarc_vars; %let n=20 ; /* number of last round. Was 17 in R18 */ %let L=537; /* Last continuous month of current round (doicm); Was 415 in R16, was 440 in R17, was 466 in R18, was 487 in R19, was 514 in R20 */ %let S=514; /* the early start of event history; was 415 in R17, was 440 in R18, was 466 in R19, was 487 in R20 */ %let I=4; /* maximum number of incarcerations */ array int_Dr(&n); array int_mr(&n); array int_yr(&n); array int_cmr(&n); array R20car(&S); *array R20arr(&S); * not used; array car(&L); array C494(&I); array C495M(&I); array C496Y(&I); array C497(&I); array C498M(&I); array C499Y(&I); array Scar(&I); /* start month of incarceration */ array Ecar(&I); /* end month of incarceration */ /* New for R17: Assigning first incarceration dates for those with 4 or more arrests to the comparable dates for those with fewer arrests */ if c443 ge 4 then do; *select cases with 4 or more arrests; c495m1=c443f; * assign month of first incarceration; c496y1=c443g_y; * assign year of first incarceration; c4971=c443g1; * still incarcerated?; c498m1=c443h; * assign end month of first incarceration; c499y1=c443i_y; * assign end year of first incarceration; end; /* R21 ROUND SPECIFIC RECODES */ /*preload for incarcerated at last interview was wrong, so too many people went through this section. Cleaning up cases so that duplicate incarcerations don't get added */ /* Cases who were not in jail at DLI but got release questions */ /* not in jail at last interview, missing release variables */ /* checked all of these cases, should set to missing */ if r20incarc_current=0 and (c438c_m in (-2,-1) or c438b_y in (-2,-1)) then do; c438a=0; c438b_y=-4; c438c_m=-4; end; /* not in jail at last interview, said never in jail */ if r20incarc_current=0 and c438b_y=1 then do; c438a=0; c438b_y=-4; c438c_m=-4; end; /* This section of the code converts response codes to years */ /* Response codes of 3 to 30 represent years for YSAQ-438B represent the years from 1997 to 2024 */ /* this section of the code. 1=I have never been in a corrections facility 2=I am still in a corrections facility */ /* CHECK THIS, and whether there need to be any hand edits */ do i=3 to 30; * check the highest response code for YSAQ-438_b; if C438B_Y=i then C438B_Y= 1997+(i-3); end; /* find date of last interview */ do i=1 to (&n); if int_cmr(i)>0 then do; dlicm=int_cmr(i); dliy =int_Yr(i); dliM =int_Mr(i); dliD =int_Dr(i); end; end; /* if month and year of release are both missing, set both to -4, set flag to 1 */ if C438B_Y in(-1 -2) & C438C_M in(-1 -2) then do; C438B_Y =-4; C438C_M=-4; de_C438=1; end; %c_month(Mo=int_m, ye=int_y, cm=doicm); if int_Y >0 then mid_month = MONTH(( MDY(int_M, int_D, int_Y) + MDY(dliM, dliD,dliY))*0.5); if int_Y>0 then do; start=dlicm + 1; * start is the continuous month after last interview; do l=1 to dlicm; if R20car(L)>0 then chk_99=1; * if prior incarceration, then chk_99=1; end; do l=start to doicm; if chk_99=1 then car(L)=99; * if previous incarceration reported, set all months since DLI to 99; else if chk_99~=1 then car(L)=0; * if not, set all months since DLI to 0; end; end; /* Flag for incarceration status at DLI */ carR20=-4; do l=1 to dlicm; if l=dlicm then carR20=R20car(L); *carR20=incarceration status at DLI; end; /* always check these cases */ /* in jail at time of DLI, but INCARC_CURRENT=0 */ /* often they are awaiting trial */ if carR20=1 & r20incarC_CURRENT=0 then do; carR20=99; *incarcerated at last interview according to array, not according to summary CV about status; cflag=1; end; if carR20=. & r20incarC_TOTNUM=0 then carR20=0; *carR20 will never be .?; if C438B_Y=2 & carR20=1 & (YHHI_4400X=7 | YFER_SAQ2_PRISONCHECK=1 ) then do; *was in jail at DLI, currently incarcerated, current dwelling is jail; scar0=start; *start of incarceration = first month after DLI; ecar0=doicm; *end of incarceration = DOI; end; /* Edit cases for C438B_Y=2 & carR20=0 & 4400r21=7 ( in prison at current interview, no prior incarceration, and has no entry dates) */ /* Incarcerated currently, but not at DLI, and has no start date */ if C438B_Y=2 & carR20=99 & YHHI_4400X=7 & (C495M1=-4 & C495M2=-4 & C495M3=-4 & C495M4=-4) then do; if Yhhi_4505 in( 1 2) then scar0=doicm; if Yhhi_4505 in( 3 ) then scar0=doicm -1; if Yhhi_4505 in( 4 ) then scar0=doicm-8; if Yhhi_4505 in( 5) then scar0=doicm-11; ecar0=doicm; nostart_flag=1; end; /* RELEASED FROM CORRECTIONS */ if C438B_Y>2 then do; * gave a valid year of release; if C438B_Y >0 & C438C_M >0 then do; * valid year and month of release; Ecar0=(C438B_Y-1980)*12+ C438C_M; * compute CM of incarceration release; if Ecar0>=start & carR20 in(1) then scar0=start; * if was incarcerated at DLI and release after DLI, first incarc date is DLI+1; if Ecar0=doicm then flag_Ecar0=1; * if release=DOI, then flag; if ecar0<=dlicm & C438B_Y>2 & C438C_M>0 & carR20=99 then edit_1=1; *incarceration release is prior to DLI; if edit_1=1 then ecar0=-4; /* delete double report */ if carR20=99 & ecar0>start then Scar0=int((dlicm+Ecar0)/2); /* missing start date */ end; /* MOVING THIS SECTION OUT OF THE IF statement above, creating flags to check */ if C438B_Y >0 & C438C_M in(-1,-2) & carR20=99 then do; ecar0=-4; /* missing month, not incarcerated at last interview */ whatif=1; end; if C438B_Y >0 & C438C_M in(-1,-2) & carR20 in (1 ) then do; /* missing month, was incarcerated at last interview */ ecar0= int((dlicm+doicm)/2); scar0=start; whatif=2; end; end;/************/ if C438B_Y in(-1 -2) & C438C_M >0 & carR20=1 then do; * incarcerated at DLI, missing end year of incarceration; if C438C_M <=int_M then C438B_Y=int_Y; if C438C_M > int_M then C438B_Y=int_Y-1; scar0=start; Ecar0=(C438B_Y-1980)*12+ C438C_M; end; /*if Ecar1> Scar2 >0 then Ecar1=Scar2-1; */ if Ecar0>0 & Scar0>0 then do; do l=Scar0 to Ecar0; car(L) =1; end; end; /***************************************************/ /* Deny in a corrections facility */ /**used mid month between DLI where indicated incarcerated or still incarcerated *and date of next interview when indicated no longer incarcerated for those * when no additional information/arrests etc. */ if C438A=1 & C438B_Y=1 & carR20=1 then do; Scar0=start; Ecar0= int((dlicm+doicm)/2); end; /* Hand edit cases for Missing start incarceration dates using using middle month if needed */ /* Valid end and start incarceration */ /* assign 1 (incarcerated) to months between start and end date of incarceration */ if Ecar0>0 & Scar0>0 then do; do l=Scar0 to Ecar0; car(L) =1; end; end; /* This accounts for cases where R reports exit date the same month as DLI */ if Ecar0=dlicm then do; c438a=0; c438b_y=-4; c438c_m=-4; DLICM_exitcheck=1; Ecar0=.; end; /* Start Sentence 2 */ do I=1 to 4;/* loop 1*/ if C495M(I)>0 & C496Y(I) then do; Scar(I) = (C496Y(I)-1980)*12+ C495M(I); if C497(I)=1 then ecar(I)=doicm; end; if C495M(I) in (-1 -2) & C496Y(I) >0 then do; Scar(I)= (C496Y(I)-1980)*12+ mid_month; if C497(I)=1 & Scar(I)>0 then Ecar(I)=doicm; end; If C498M(I)>0 & C499Y(I)>0 then do; * those with an exit date; Ecar(I) = (C499Y(I)-1980)*12+ C498M(I); if Ecar(I)>0 & Ecar(I)=doicm then flag_ecar=1; end; if C498M(I) in (-1 -2) & C499Y(I) >0 then do; if int_Y=C499Y(I) then Ecar(I)=(C499Y(I)-1980)*12+ mid_month ; Ecar(I)= (C499Y(I)-1980)*12+ mid_month; if Ecar(I)0 & 00 & ecar3>0 | scar2=scar1 & ecar2=ecar1 & scar1>0 & ecar1>0 then do; flag_d=1; end; if scar3=scar1 & ecar3=ecar1 & scar1>0 & ecar1>0 then do; flag_d=2; end; if flag_d=1 then do; scar2 = .; ecar2 = .; end; if flag_d=2 then do; scar3 = .; ecar3 = .; end; if Ecar(I)>0 & Scar(I)>0 & scar(I)> ecar(I) then wrong = 1; if Ecar(I)>0 & Scar(I)>0 then do; do l=Scar(I) to Ecar(I); car(L) =1; end; end; if Ecar(I)>0 then do; do l=Ecar(I)+1 to doicm ; if car(L) ~=1 then car(L)=99; end; end; end; if int_y>0 then do; array sarr_p /*scar0 */scar1- scar4; *; array cvm cvm1-cvm4; array cvy cvy1-cvy4; array cvmy cvmy1-cvmy4; array fir firstc540-firstc157; * EACH ROUND: change array R20: was 516 to 157, R19: was 492 to 157, R18: was 468 to 157, R17: was 444 to 157, R20 is 516 (Dec 2022); array AGEYEAR AGEYR1-AGEYR4; do over sarr_p; if sarr_p>0 then do; do i=540 to 157 by -12; * CHANGE was R16: 420 Dec 2014 r17: 444 (dec 2016) r18: 468 (Dec 2018) r19: 492 (Dec 2020) r20: 516 (Dec 2022) */; fir=i; if fir-11<=sarr_p<=fir then do; cvm=sarr_p-(fir-12); /* 10/05= 310 10=310-(312-12) */ cvy=(sarr_p-cvm)/12+1980; cvmy=cvy*100+cvm; end; end; end; end; /* use for checking */ do l=start to doicm; if car(L)=1 then chk_1=1; *IDs cases where incarcerated at some point since DLI, according to arrays; end; /* First incarceration data */ INCARC_FIRST_21=-4; if carR20=0 then INCARC_FIRST_21= min(of cvmy:); * never previously incarcerated; end; if carR20=0 & INCARC_FIRST_21 >0 then INCARC_FIRST=INCARC_FIRST_21; else if INCARC_FIRST_21<=0 then INCARC_FIRST=r20incarC_FIRST; if r20incarc_first=-3 then incarc_first=-3; /* Total number of incarceration This is only Temporary*/ INCARC_TOTNUM_21=0; do i = 1 to 4; if scar(i)>0 then do; /*INCARC_TOTNUM_16=1;*/ INCARC_TOTNUM_21 = INCARC_TOTNUM_21 + 1; /* TEST: limiting to i=3 */ if i le 3 then do; if /*scar(i) =scar(i+1) & scar(i)>0 &*/ ecar(i)>0 & ecar(i)=ecar(i+1) then chk_d=1; end; if chk_d =1 & ecar(i) >0 then out=i; end; end; if out>0 then INCARC_TOTNUM_21= out /*INCARC_TOTNUM_16-out + 1; */; INCARC_TOTNUM=INCARC_TOTNUM_21 + r20incarC_TOTNUM; /* was previously arrested/arrested since DLI/prior arrest then total add one to total */ if carR20=99 & scar0>dlicm & r20incarC_TOTNUM>0 then INCARC_TOTNUM=r20incarC_TOTNUM+1 ; /* missing values */ if r20incarc_totnum=-3 then incarc_totnum=-3; INCARC_AGE_FIRST=-4; do over cvmy; if carR20=0 & cvmy>0 then do; if (cvy>0 and bdate_y>0 and cvm>0 and bdate_m>0) then INCARC_AGE_FIRST_21 =(cvy-bdate_y)*12+ (cvm-bdate_m); end; end; do over cvmy; if carR20=0 & cvmy>0 & int_y>0 & bdate_y>0 then do; if cvm>=bdate_m then AGEYEAR=cvy-bdate_y; else if 00 then INCARC_AGE_FIRST=INCARC_AGE_FIRST_21; else INCARC_AGE_FIRST=r20incarC_AGE_FIRST; if r20incarc_age_first=-3 then incarc_age_first=-3; /* INCARC_LENGTH_FIRST */ /* For the first time incarceration at current round */ count_1=0; count_1a=0; count_1b=0; count_2=0; count_B=0; count_tot=0; /* some of these start or end dates are -4, which is problematic for using the min */ /* what happens to those with 3 incarcerations? CHECK FOR CASES WITH 3 OR MORE INCARCERATIONS, THIS MAY NOT PICK UP THE LONGEST!!*/ start_1 = min(of scar0 scar1- scar4); end_1 = min(of ecar0 ecar1- ecar4); start_2 = max(of scar0 scar1- scar4); end_2 = max(of ecar0 ecar1- ecar4); if start_1>0 then do ; *COUNT_1 is length of first incarc reported this round; do l=start_1 to doicm until(car(L)=99); if car(L)=1 then count_1=count_1+1; end; do L=start_1 to doicm ; if car(L)=1 then count_tot=count_tot+1; *COUNT_TOT counts total months incarcerated this round; end; end; if scar1>0 & (scar2>0 or scar3>0 or scar4>0) then do; * originally just checked scar2>0; do l=start_2 to doicm ; if car(L)=1 then count_1a=count_1a+1; * count1_a is count of months incarcerated starting at second start date (doesnt stop at 99 as above); end; end; if scar0>0 & (scar1>0 or scar2>0 or scar3>0 or scar4>0) then do; do l=start_2 to doicm ; if car(L)=1 then count_1b=count_1b+1; /* count1_b is count of months incarcerated starting at second start date when the first is a current at DLI incarceration;*/ end; /*check count_1b created correctly */ end; if r20incarC_LENGTH_FIRST <=0 then INCARC_LENGTH_FIRST= count_1; if r20incarC_LENGTH_FIRST >0 then INCARC_LENGTH_FIRST= r20incarC_LENGTH_FIRST; if r20incarC_LENGTH_FIRST >0 & carR20= 1 & r20incarC_TOTNUM =1 then INCARC_LENGTH_FIRST= r20incarC_LENGTH_FIRST +count_1; if INCARC_TOTNUM = 0 then INCARC_LENGTH_FIRST=-4; if r20incarc_length_first=-3 then incarc_length_first=-3; /* incarceration at before current round */ if carR20=1 & start_1>0 & r20incarC_TOTNUM >1 then do; do L= dlicm to 200 by -1 until(R20car(L) in( 99, 0)); if R20car(L)=1 then count_B=count_B+1; end; count_2 = count_B+ count_1; end; /* For the longest length of incarceration */ INCARC_LENGTH_LONGEST= max(count_1, count_1a, count_1b, count_2, INCARC_LENGTH_FIRST,r20incarC_LENGTH_LONGEST); *check this; if INCARC_TOTNUM = 0 then INCARC_LENGTH_LONGEST =-4; INCARC_TOTMONTHS = count_tot + r20incarC_TOTMONTHS; /* addint additional check for missing values */ if r20incarc_totmonths=-3 then incarc_totmonths=-3; if r20incarc_length_longest=-3 then incarc_length_longest=-3; /* INCARC_CURRENT */ if int_Y<0 then do; INCARC_CURRENT=R20INCARC_CURRENT; end; if int_Y>0 then do; INCARC_CURRENT=0; do L= doicm ; if car(L)=1 then INCARC_CURRENT=1; if INCARC_CURRENT=1 & (flag_ecar=1 | flag_ecar0=1) then INCARC_CURRENT=0; end; end; /* Non-interviews */ if int_Y in(-4 -5) then do; do l=dlicm+1 to 537; * check!!!! r21 changed from 514 to 537, r20 changed from 487 to 514, r19 changed from 466 to 487, r18 CHANGED FROM 440 TO 466, R17: changed from 415 to 440; car(L)=-5; end; end; do l=207 to 537; * r21 changed from 514 to 537, r20 changed from 487 to 514, r19 changed from 466 to 487, r18 CHANGED FROM 440 TO 466, R17: changed from 415 to 440; * earliest dli is feb 1997 (march 1997 is cm 207); if car(L) in(. -5) then car(L)=-4; end; /* Assigns -4s to months prior to DLI */ do l=207 to dlicm; car(L)=-4; end; /* INCARC_INCOMPLETE CODE */ /* This code agrees with hand edited CV, but might still have some loopholes for special cases */ if c443 gt 3 then do; if ysaqf_443d=0 then r21incarc_incomplete=0; if ysaqf_443c2a=0 then r21incarc_incomplete=0; if ysaqf_443d=1 then do; if c443f gt 0 and c443g_y ge 0 and ysaqf_443a3 ge 0 and ysaqf_443a4_y ge 0 then do; if c443g_y gt ysaqf_443a4_y then r21incarc_incomplete=0; else if c443g_y eq ysaqf_443a4_y then do; if c443f ge YSAQF_443A3 then r21incarc_incomplete=0; else if c443f lt YSAQF_443A3 then r21incarc_incomplete=1; end; else r21incarc_incomplete=1; END; If R21INCARC_INCOMPLETE=. THEN R21INCARC_INCOMPLETE=1; If R20INCARC_INCOMPLETE=1 then R21INCARC_INCOMPLETE=1; end; end; if r21incarc_incomplete ge 0 then incarc_incomplete=r21incarc_incomplete; else incarc_incomplete=r20incarc_incomplete; run; /* create final files */ DATA OLDONE; SET ONE; RUN; PROC COMPARE DATA=ONE COMPARE=OLDONE; ID pubid; RUN; data r21incar.R21ev_incarc; set one ; keep pubid car207-car537; run; proc export data=r21incar.r21ev_incarc dbms=xlsx outfile='J:\R21 Incarceration\Output\R21incarc_ev.xlsx' replace; sheet='data'; run; data r21incar.R21cv_incarc; set one; keep pubid INCARC_FIRST INCARC_AGE_FIRST INCARC_TOTNUM INCARC_LENGTH_FIRST INCARC_LENGTH_LONGEST INCARC_TOTMONTHS INCARC_CURRENT INCARC_INCOMPLETE; run; proc freq data=r21incar.r21cv_incarc; tables incarc_:; run; proc export data=r21incar.r21cv_incarc dbms=xlsx outfile='J:\R21 Incarceration\Output\R21incarc_cv.xlsx' replace; sheet='data'; run;