*  Creating Waiting Children file--Use "in-care last day" file

* xxxx.sav - replace with a file name you create.

*Selects children who are legally free for adoption (Both parents with a TPR date) also
  included are child records with one parental TPR date and "Parents Died" selected as
  "Circumstances associated with removal".  These children (one "TPR" and "Parents Died")
   are assumed to be legally free for adoption.

recode prtmomda prtdadda (sysmis=99).

compute selector =2.

if(casegoal=3)selector=1.
if (prtmomda~=99 and prtdadda~=99 and casegoal~=3) selector=1.
if(prtmomda=99 and prtdadda~=99 and prtsdied=1 and casegoal ~=3) selector=1.
if(prtmomda~=99 and prtdadda=99 and prtsdied=1 and casegoal~=3) selector=1.
formats selector (f1.0).
FILTER OFF.
USE ALL.
SELECT IF(selector = 1).
EXECUTE .


save outfile ="c:\xxxx.sav".

* compute TPR's

recode prtmomda prtdadda (sysmis=99).
compute tpr=2.
if (prtmomda~=99 and prtdadda~=99) tpr=1.
if (prtmomda=99 and prtdadda~=99 and prtsdied=1) tpr=1.
if(prtmomda~=99 and prtdadda=99 and prtsdied=1) tpr=1.
formats selector (f1.0).
variable label tpr "Termination of Parental Rights".
value labels tpr 1 'Yes' 2 'No'.
execute. 

*Child's age at end of reporting period

COMPUTE age = (YRMODA(1998,9,30)-YRMODA(dobyr,dobmo,dobda))/365.25 .
EXECUTE .
RECODE
  age  (Lowest thru 0=SYSMIS)  (18 thru Highest=SYSMIS)  .
EXECUTE .

RECODE
  age
 (SYSMIS=7) (19 thru Highest=6)  (16 thru 19=5)  (11 thru 16=4)  (6 thru 11=3)
  (1 thru 6=2)  (Lowest thru 1=1)  INTO  gage.
FORMATS gage (F2.0).
variable labels gage "Child's Age (Grouped) At End of Reporting Period".
value labels gage 7'unknown' 6 'Over 18' 5 '16-18' 4 '11-15' 3 '6-10' 2 '1-5' 1 'less than 1'.
EXECUTE .


*  Race/ethnic categories

DO IF (race = 1 & hisorgin = 1 | race = 2 & hisorgin = 1 | race = 3 &
  hisorgin = 1 | race = 4 & hisorgin = 1 | race = 5 & hisorgin=1) .
RECODE
  race
  (1=5)  (2=5)  (3=5)  (4=5)  (5=5) INTO  racethnc.
END IF .
DO IF (race = 1 & hisorgin =2 | race = 2 & hisorgin = 2 | race = 3 &
  hisorgin = 2 | race = 4 & hisorgin = 2 | race = 5 & hisorgin = 2) .
RECODE
  race
    (1=1) (2=2) (3=3) (4=4) (5=6) into racethnc.
end if.
DO IF (race = 1 & hisorgin = 3 | race = 2 & hisorgin = 3 | race = 3 &
  hisorgin = 3 | race = 4 & hisorgin = 3 | race = 5 & hisorgin = 3) .
RECODE
  race
    (1=1) (2=2) (3=3) (4=4) (5=6) into racethnc.
end if.
DO IF (race = 1 & missing(hisorgin) | race = 2 & missing(hisorgin) | race = 3 &
  missing(hisorgin) | race = 4 & missing(hisorgin) | race = 5 & missing(hisorgin)) .
RECODE
  race
    (1=1) (2=2) (3=3) (4=4) (5=6) into racethnc.
end if.
DO IF (MISSING(RACE)& HISORGIN = 1).
RECODE
 RACE
 (SYSMIS=5) INTO racethnc.
END IF.
DO IF (MISSING(RACE)& HISORGIN = 2).
RECODE
 RACE
 (SYSMIS=6) INTO racethnc.
END IF.
 DO IF (MISSING(RACE)& HISORGIN = 3).
RECODE
 RACE
 (SYSMIS=6) INTO racethnc.
END IF.
DO IF (MISSING(RACE) & MISSING(HISORGIN)).
END IF.
FORMATS RACETHNC (F1.0).
 value labels racethnc
   1 'White Non-Hispanic'
   2 'Black Non-Hispanic'
   3 'AI/AN Non-Hispanic'
   4 'Asian/PI Non-Hispanic'
   5 'Hispanic'
   6 'UnKnown/Unable to Determine'.

Variable labels racethnc "Child's Race/Ethnicity".
recode racethnc (1=1) (2=2) (3=5) (4=4) (5=3) (6=6) (SYSMIS=6).
value labels  racethnc
   1 'White Non-Hispanic'
   2 'Black Non-Hispanic'
   3 'Hispanic'
   4 'Asian/PI Non-Hispanic'
   5 'AI/AN Non-Hispanic'
   6 'UnKnown/Unable to Determine'.


FILTER OFF.
USE ALL.
SELECT IF((casegoal <= 7 & gage <= 4) OR(casegoal NE 5 &  gage >=5)).
EXECUTE .

save outfile ="c:\xxxx.sav".
  
FREQUENCIES
  VARIABLES=state
  /ORDER  ANALYSIS .
* General Tables.
TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000002 "Total" $t000001 "Total"
  /TABLE=state + $t000002  BY tpr > (STATISTICS) + $t000001
  /STATISTICS
  count( state( F5.0 ))
  cpct( state( PCT5.1 ) 'Row %':state ) /TITLE  'Termination of Parental'+
 ' Rights--9/30/98'.
* General Tables.
TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000002 "Total" $t000003 "Total"
  /TABLE=state + $t000002  BY gage > (STATISTICS) + $t000003
  /STATISTICS
  count( state( F5.0 ))
  cpct( state( PCT5.1 ) 'Row %':state ) /TITLE  'Age Distrbution for Waiting'+
 ' Children--9/30/98'.
* General Tables.
TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000002 "Total" $t000004 "Total"
  /TABLE=state + $t000002  BY racethnc > (STATISTICS) + $t000004
  /STATISTICS
  count( state( F5.0 ))
  cpct( state( PCT5.1 ) 'Row %':state ) /TITLE  'Race/Ethnic Distrbution for'+
 ' Waiting Children--9/30/98'.

*  Use with Annual Adoption File


*Child's age at finalization -- ungrouped and grouped

COMPUTE agfinl = (YRMODA(finadpyr,finadpmo,finadpda)-YRMODA(dobyr,dobmo,1))/365.25 .
EXECUTE .
variable labels agfinl "Child's Finalization Age" .

RECODE
 agfinl
  (SYSMIS=7) (19 thru Highest=6)  (16 thru 19=5)  (11 thru 16=4)  (6 thru 11=3)
  (1 thru 6=2)  (Lowest thru 1=1)  INTO  AGEg.
FORMATS ageg(F2.0).
variable labels ageg "Child's Finalization Age (Grouped)".
value labels ageg 7 'unknown' 6 '19+' 5 '16-18' 4 '11-15' 3 '6-10' 2 '1-5' 1 'under 1 '.
EXECUTE .


*  Race/ethnic categories

DO IF (race = 1 & hisorgin = 1 | race = 2 & hisorgin = 1 | race = 3 &
  hisorgin = 1 | race = 4 & hisorgin = 1 | race = 5 & hisorgin=1) .
RECODE
  race
  (1=5)  (2=5)  (3=5)  (4=5)  (5=5) INTO  racethnc.
END IF .
DO IF (race = 1 & hisorgin =2 | race = 2 & hisorgin = 2 | race = 3 &
  hisorgin = 2 | race = 4 & hisorgin = 2 | race = 5 & hisorgin = 2) .
RECODE
  race
    (1=1) (2=2) (3=3) (4=4) (5=6) into racethnc.
end if.
DO IF (race = 1 & hisorgin = 3 | race = 2 & hisorgin = 3 | race = 3 &
  hisorgin = 3 | race = 4 & hisorgin = 3 | race = 5 & hisorgin = 3) .
RECODE
  race
    (1=1) (2=2) (3=3) (4=4) (5=6) into racethnc.
end if.
DO IF (race = 1 & missing(hisorgin) | race = 2 & missing(hisorgin) | race = 3 &
  missing(hisorgin) | race = 4 & missing(hisorgin) | race = 5 & missing(hisorgin)) .
RECODE
  race
    (1=1) (2=2) (3=3) (4=4) (5=6) into racethnc.
end if.
DO IF (MISSING(RACE)& HISORGIN = 1).
RECODE
 RACE
 (SYSMIS=5) INTO racethnc.
END IF.
DO IF (MISSING(RACE)& HISORGIN = 2).
RECODE
 RACE
 (SYSMIS=6) INTO racethnc.
END IF.
 DO IF (MISSING(RACE)& HISORGIN = 3).
RECODE
 RACE
 (SYSMIS=6) INTO racethnc.
END IF.
DO IF (MISSING(RACE) & MISSING(HISORGIN)).
END IF.
FORMATS RACETHNC (F1.0).
 value labels racethnc
   1 'White Non-Hispanic'
   2 'Black Non-Hispanic'
   3 'AI/AN Non-Hispanic'
   4 'Asian/PI Non-Hispanic'
   5 'Hispanic'
   6 'UnKnown/Unable to Determine'.

Variable labels racethnc "Child's Race/Ethnicity".
recode racethnc (1=1) (2=2) (3=5) (4=4) (5=3) (6=6) (SYSMIS=6).
value labels  racethnc
   1 'White Non-Hispanic'
   2 'Black Non-Hispanic'
   3 'Hispanic'
   4 'Asian/PI Non-Hispanic'
   5 'AI/AN Non-Hispanic'
   6 'UnKnown/Unable to Determine'.




FREQUENCIES
  VARIABLES=state
  /ORDER  ANALYSIS .
* General Tables.
TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total" $t000002 "Total"
  /TABLE=state + $t000001  BY ageg > (STATISTICS) + $t000002
  /STATISTICS
  count( state( F5.0 ))
  cpct( state( PCT5.1 ) 'Row %':state ) /TITLE  'Age at Finalization'.
* General Tables.
TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total" $t000003 "Total"
  /TABLE=state + $t000001  BY racethnc > (STATISTICS) + $t000003
  /STATISTICS
  count( state( F5.0 ))
  cpct( state( PCT5.1 ) 'Row %':state ) /TITLE  'Race/ethnicity of Child'.