*State Data Profile Pt-in-Time Syntax Program for Final State Assessment 98c
*To use, change from "EZ" to ST name to call up appropriate files

********State Data Profile Pt-in-Time Section I--Population Flow Numbers*************

get file 'c:\cfsr\EZdata\EZinc1st98c.sav'.
compute LOS1 = (yrmoda(97,10,01)-yrmoda(latremyr,latremmo,latremda))/30.4375.
RECODE
  LOS1  (252 thru Highest=SYSMIS).
DO IF (LOS1 <= 0).
RECODE
  LOS1  (Lowest thru 0=SYSMIS).
END IF .
EXECUTE .
do if (missing(los1)).
compute service=2.
else.
Compute service=1.
end if.
formats service (f1.0).
value labels service
1 'Records'
2 'Missing'.
exe.
* General Tables.
TABLES
  /FORMAT BLANK MISSING('.')
  /OBSERVATION= los1
  /GBASE=CASES
  /FTOTAL= $t000001 "Total"
  /TABLE=state + $t000001  BY los1 + service
  /STATISTICS
  median( los1( F5.2 ))
  count( service( COMMA6.0 ) 'N')/Title 'Children in Care on first day FY98 (10/1/97)'.

get file 'c:\cfsr\EZdata\EZentry98C.sav'.
Compute Records = (1).
formats Records (f1.0).
* General Tables.
TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total"
  /TABLE=state + $t000001  BY records
  /STATISTICS
  count( records( COMMA6.0 ) 'N')/Title 'Children Entering Care During  FY98'.

get file 'c:\cfsr\EZdata\EZexits98C.sav'.
compute LOS1 = (yrmoda(dodfcyr,dodfcmo,dodfcda)-yrmoda(latremyr,latremmo,latremda))/30.4375.
RECODE
  LOS1  (252 thru Highest=SYSMIS).
DO IF (LOS1 <= 0).
RECODE
  LOS1  (Lowest thru 0=SYSMIS).
END IF .
EXECUTE .
do if (missing(los1)).
compute service=2.
else.
Compute service=1.
end if.
formats service (f1.0).
value labels service
1 'Records'
2 'Missing'.
exe.
* General Tables.
TABLES
  /FORMAT BLANK MISSING('.')
  /OBSERVATION= los1
  /GBASE=CASES
  /FTOTAL= $t000001 "Total"
  /TABLE=state + $t000001  BY los1 + service
  /STATISTICS
  median( los1( F5.2 ))
  count( service( COMMA6.0 ) 'N')/Title 'Children Exiting Care During FY98 (N+Missing=Total)'.

get file 'c:\cfsr\EZdata\EZinc98C.sav'.
compute LOS1 = (yrmoda(98,09,30)-yrmoda(latremyr,latremmo,latremda))/30.4375.
RECODE
  LOS1  (252 thru Highest=SYSMIS).
DO IF (LOS1 <= 0).
RECODE
  LOS1  (Lowest thru 0=SYSMIS).
END IF .
EXECUTE .
do if (missing(los1)).
compute service=2.
else.
Compute service=1.
end if.
formats service (f1.0).
value labels service
1 'Records'
2 'Missing'.
exe.
* General Tables.
TABLES
  /FORMAT BLANK MISSING('.')
  /OBSERVATION= los1
  /GBASE=CASES
  /FTOTAL= $t000001 "Total"
  /TABLE=state + $t000001  BY los1 + service
  /STATISTICS
  median( los1( F5.2 ))
  count( service( COMMA6.0 ) 'N')/Title 'Children in Care on last day FY98 (N+Missing=Total)'.

********************State Data Profile Pt-in-Time Sections II, III, IV, and V**********************

get file 'c:\cfsr\EZdata\EZinc98C.sav'.
compute settime = yrmoda(cursetyr,cursetmo,cursetda).
formats settime (f6.0).
do if (settime<=yrmoda(1998,09,30)).
compute set=1.
else if (settime>=yrmoda(1998,10,01)).
compute set=2.
formats set (f1.0).
end if.
compute newplace=(numplep).
formats newplace (f2.0).
if (set=2 and (newplace>=2)) newplace = (newplace-1).
exe.
recode newplace
(sysmis=9) (0=9) (1=1) (2=2) (3=3) (4=4) (5=5) (6 thru highest=6) into NewP.
formats NewP (f1.0).
variable labels NewP 'Total Number of Placements'.
value labels NewP
1 '1 Placement'
2 '2 Placements'
3 '3 Placements'
4 '4 Placements'
5 '5 Placements'
6 '6 Placements or More'
9 'Missing'.

recode casegoal
(sysmis=9) (0=9).
value labels casegoal
1 'Reunification'
2 'Live with Relatives'
3 'Adoption'
4 'Long-Term Foster Care'
5 'Emancipation'
6 'Guardianship'
7 'Not Yet Established'
9 'Missing Goal Info'.
exe.

recode curplset 
(sysmis=9) (0=9).
if (set=2) curplset=9.5.
value labels curplset
1 'Pre-Adoptive Homes'
2 'FFH-Relative'
3 'FFH-NonRelative'
4 'Group Home'
5 'Institution'
6 'Supervised IL'
7 'Runaway'
8 'Trial Home Visit'
9 'Missing' 
9.5 'Not applicable'.

recode totalrem
(sysmis=9) (0=9) (1=1) (2=2) (3=3) (4=4) (5=5) (6 thru highest=6).
value labels totalrem
1 '1 Removal'
2 '2 Removals'
3 '3 Removals'
4 '4 Removals'
5 '5 Removals'
6 '6 Removals or More'
9 'Missing'.
frequencies variables curplset casegoal NewP totalrem.
exe.

**********************State Data Profile Pt-in-Time Section VI*****************************
*********************Compute 17 of 22 months using Incare file***************************

get file 'c:\cfsr\EZdata\EZinc98C.sav'.
RECODE
  prtmomda prtdadda  (SYSMIS=99).
EXECUTE .
do if (curplset=1 or curplset=2 or prtmomda~=99 or prtdadda~=99).
compute status=1.
else. 
compute status=2.
formats status (f1.0).
end if.
value labels status
1 'Exclude'
2 'Include'.
execute.

use all.
filter off.
select if (status=2).
execute.

do if (yrmoda(latremyr,latremmo,latremda)<151410).
	compute allos=(151927-(yrmoda(latremyr,latremmo,latremda)))/30.4375.

else if (totalrem=1 and (yrmoda(latremyr,latremmo,latremda)<151410)).
	compute allos=(151927-(yrmoda(latremyr,latremmo,latremda)))/30.4375.

else if (totalrem=1 and (yrmoda(latremyr,latremmo,latremda)>151409)).
	compute allos=(151927-yrmoda(latremyr,latremmo,latremda))/30.4375.

else if (totalrem=2 and ((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151259)) and
                        (yrmoda(latremyr,latremmo,latremda)<151259)).
	compute allos=(151927-yrmoda(latremyr,latremmo,latremda))/30.4375.

else if (totalrem=2 and ((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151259) and
                        (yrmoda(latremyr,latremmo,latremda)>151258))).
	compute allos=(151927-yrmoda(latremyr,latremmo,latremda))/30.4375.

else if (totalrem=2 and (((yrmoda(rem1yr,rem1mo,rem1da)<151259) and
                         ((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151410) and
                          (yrmoda(dlstfcyr,dlstfcmo,dlstfcda)>151258)))and
                          (yrmoda(latremyr,latremmo,latremda)>151258))).
	compute allos=((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)-151259)+
               (151927-yrmoda(latremyr,latremmo,latremda)))/30.4375.

else if (totalrem=2 and (((yrmoda(rem1yr,rem1mo,rem1da)<151259) and
                         ((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151927) and
                          (yrmoda(dlstfcyr,dlstfcmo,dlstfcda)>151409)))and
                          (yrmoda(latremyr,latremmo,latremda)>151409))).
	compute allos=((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)-151259)+
               (151927-yrmoda(latremyr,latremmo,latremda)))/30.4375.

else if (totalrem=2 and ((((yrmoda(rem1yr,rem1mo,rem1da)<151410) and
                          (yrmoda(rem1yr,rem1mo,rem1da)>151258)) and
                          ((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151410)and
                          (yrmoda(latremyr,latremmo,latremda)<151928)))and
                          (yrmoda(latremyr,latremmo,latremda)>151258))).
	compute allos=((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)-
                yrmoda(rem1yr,rem1mo,rem1da))+
               (151927-yrmoda(latremyr,latremmo,latremda)))/30.4375.

else if (totalrem=2 and (((yrmoda(rem1yr,rem1mo,rem1da)<151410) and
                          (yrmoda(rem1yr,rem1mo,rem1da)>151258)) and
                          ((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)>151409)and
                          (yrmoda(latremyr,latremmo,latremda)>151409)))).
	compute allos=((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)-
                yrmoda(rem1yr,rem1mo,rem1da))+
               (151927-yrmoda(latremyr,latremmo,latremda)))/30.4375.

else if (totalrem=2 and (((yrmoda(rem1yr,rem1mo,rem1da)>151409)) and
                          ((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)>151409)and
                          (yrmoda(latremyr,latremmo,latremda)>151409)))).
	compute allos=((yrmoda(dlstfcyr,dlstfcmo,dlstfcda)-
                yrmoda(rem1yr,rem1mo,rem1da))+
               (151927-yrmoda(latremyr,latremmo,latremda)))/30.4375.

else if (totalrem=3 and(yrmoda(latremyr,latremmo,latremda)<151259) and
		(yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151259)).
	compute allos=(151927-yrmoda(latremyr,latremmo,latremda))/30.4375.

else if (totalrem=3 and ((yrmoda(latremyr,latremmo,latremda)<151928) and
		 (yrmoda(latremyr,latremmo,latremda)>151409) and
		 (yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151259))).
	compute allos=(151927-yrmoda(latremyr,latremmo,latremda))/30.4375.

else if (totalrem=3 and ((yrmoda(latremyr,latremmo,latremda)>151258) and
		 (yrmoda(latremyr,latremmo,latremda)<151410) and
		 (yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151410))).
	compute allos=(151927-yrmoda(latremyr,latremmo,latremda))/30.4375.

else if (totalrem>3 and(yrmoda(latremyr,latremmo,latremda)<151259) and
		(yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151259)).
	compute allos=(151927-yrmoda(latremyr,latremmo,latremda))/30.4375.

else if (totalrem>3 and ((yrmoda(latremyr,latremmo,latremda)>151258) and
		 (yrmoda(latremyr,latremmo,latremda)<151410) and
		 (yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151410))).
	compute allos=(151927-yrmoda(latremyr,latremmo,latremda))/30.4375.

else if (totalrem>3 and ((yrmoda(latremyr,latremmo,latremda)<151928) and
		 (yrmoda(latremyr,latremmo,latremda)>151409) and
		 (yrmoda(dlstfcyr,dlstfcmo,dlstfcda)<151259))).
	compute allos=(151927-yrmoda(latremyr,latremmo,latremda))/30.4375.

end if.
execute.
recode allos
(17 thru highest=1) (16 thru 17=2) (15 thru 16=3)
(14 thru 15=4)(lowest thru 14=5) into ConsdTPR.
formats ConsdTPR (f1.0).
value labels ConsdTPR
1 '17 of 22 months in care'
2 'TPR in 1 Month or Less'
3 'TPR in 2 Months or Less'
4 'TPR in 3 Months or Less'
5 'TPR in 4 Months or More'.
frequencies ConsdTPR.
execute.

******************************State Data Profile Pt-in-Time Section VIII***********************************

get file 'c:\cfsr\EZdata\EZexits98C.sav'.
compute LOS1 = (yrmoda(dodfcyr,dodfcmo,dodfcda)-yrmoda(latremyr,latremmo,latremda))/30.4375.
RECODE
  LOS1  (252 thru Highest=SYSMIS).
DO IF (LOS1 <= 0).
RECODE
  LOS1  (Lowest thru 0=SYSMIS).
END IF .
recode los1
	(sysmis=9) into Missing.
formats missing (f1.0).
EXECUTE .
recode disreasn (sysmis=9) (0=9) (1=1) (2=1) (3=3) (5=5)(else=8) into Newdis1.
formats Newdis1 (f1.0).
value labels Newdis1
1'Reunification/Relative Pl'
3'Adoption'
5'Guardianship'
8'Other'
9 'Missing'.
exe.

* Generate Table for Pt-in-Time Profile VIII.

TABLES
  /FORMAT BLANK MISSING('.')
  /OBSERVATION= los1
  /GBASE=CASES
  /FTOTAL= $t000001 "Total"
  /TABLE=newdis1 + $t000001  BY los1 + missing
  /STATISTICS
  validn( los1( COMMA6.0 ) 'N')
  median( los1( F5.2 ) 'Median Mos')
  count( missing( F5.0 )).

*************************State Data Profile Pt-in-Time Section IX**********************************

*Of all children who were reunified with their parents or caretakers at the time of discharge
*from foster care, what percentage was reunified in 12 month time intervals.


get file 'c:\cfsr\EZdata\EZExits98C.sav'.
recode disreasn
(sysmis=9) (0=9) (1=1) (2=1) (3=3) (4=4) (5=5) (else=8) into newdis.
formats newdis (f1.0).
value labels newdis
1 'Reunify'
3 'Adoption'
4 'Emancipation'
5 'Guardianship'
8 'Other'
9 'Missing'.
compute LOS = (yrmoda(dodfcyr,dodfcmo,dodfcda)-
                yrmoda(latremyr,latremmo,latremda))/30.4375.
RECODE
  LOS  (252 thru Highest=SYSMIS).
DO IF (LOS <= 0).
RECODE
  LOS (Lowest thru 0=SYSMIS).
END IF .
recode los
(sysmis=9) (48 thru highest=5) (36 thru 48=4) (24 thru 36=3) (12 thru 24=2) (lowest thru 12=1) into LOS1.
formats los1 (f1.0).
value labels los1
1'Los<12Ms'
2'12Ms<=Los<24Ms'
3'24Ms<=Los<36Ms'
4'36Ms<=Los<48Ms'
5'Los>=48Ms'
9'Missing'.

Temporary.
Select if (newdis=1).
TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total" $t000002 "Total"
  /TABLE=state + $t000001  BY los1 + $t000002
  /STATISTICS
  count( los1( COMMA6.0 ) 'N')
  cpct( los1( PCT5.2 ) 'Row %':state )
  count( $t000002( COMMA7.0 ) 'N')/Title 'FY98 Pt-in-Time Profile IX.'.

*********************State Data Profile Pt-in-Time Section X********************************************

*Of all children who entered care, what percentage exited care in less than 24 months?

get file 'c:\cfsr\EZdata\EZExits98C.sav'.
recode disreasn 
(sysmis=9) (0=9) (1=1) (2=1) (3=3) (5=5)(else=8) into Newdis1.
value labels Newdis1
1'Reunification'
3'Adoption'
5'Guardianship'
8'Other'
9'Missing'.
formats Newdis1 (f1.0).
compute LOS = (yrmoda(dodfcyr,dodfcmo,dodfcda)-
                yrmoda(latremyr,latremmo,latremda))/30.4375.
RECODE
  LOS  (252 thru Highest=SYSMIS).
DO IF (LOS <= 0).
RECODE
  LOS (Lowest thru 0=SYSMIS).
END IF .
exe.
recode los
(sysmis=9) (48 thru highest=4) (36 thru 48=3) (24 thru 36=2) (lowest thru 24=1) into LOS1.
formats los1 (f1.0).
value labels los1
1'Los<24Ms'
2'24Ms<=Los<36Ms'
3'36Ms<=Los<48Ms'
4'Los>=48Ms'
9'Missing'.
exe.

Temporary.
Select if (Newdis1=3).
TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total" $t000002 "Total"
  /TABLE=state > newdis1 + $t000001  BY los1 + $t000002
  /STATISTICS
  count( los1( COMMA6.0 ) 'N')
  cpct( los1( PCT5.2 ) 'Row %':state newdis1 )
  count( $t000002( COMMA5.0 ) 'N')/Title 'FY98 Pt-in-Time Profile X.'.


************************State Data Profile Pt-in-Time Section XI************************************************

*Of all children served who have been in care for 12 month intervals, what percent have had
*no more than two placements settings during that time period? 

get file 'c:\cfsr\EZdata\EZserved98C.sav'.
do if ((missing(dodfcyr)  and missing(dodfcmo) and missing(dodfcda)) or 
       (yrmoda(dodfcyr,dodfcmo,dodfcda)>=yrmoda(1998,10,01))).
compute LOS=(yrmoda(1998,09,30)-yrmoda(latremyr,latremmo,latremda))/30.4375.
else. 
compute LOS=(yrmoda(dodfcyr,dodfcmo,dodfcda)-yrmoda(latremyr,latremmo,latremda))/30.4375.
end if.
RECODE
  LOS  (252 thru Highest=SYSMIS).
DO IF (LOS <=0).
RECODE
  LOS  (Lowest thru 0=SYSMIS).
END IF .
exe.
recode los
(sysmis=9) (48 thru highest=5) (36 thru 48=4) (24 thru 36=3) (12 thru 24=2) (lowest thru 12=1) into LOS2.
formats los2 (f1.0).
value labels los2
1'Los<12Ms'
2'12Ms<=Los<24Ms'
3'24Ms<=Los<36Ms'
4'36Ms<=Los<48Ms'
5'Los>=48Ms'
9'Missing'.
variable labels Los2 'Time in Care'.
compute settime = yrmoda(cursetyr,cursetmo,cursetda).
formats settime (f6.0).
do if (settime<=151927).
compute set=1.
else if (settime>=151928).
compute set=2.
formats set (f1.0).
end if.
compute newplace=(numplep).
formats newplace (f2.0).
if (set=2 and (newplace>=2)) newplace = (newplace-1).
exe.
recode newplace
(sysmis=9) (0=9) (lowest thru 2=1) (3 thru highest=2) into NewP.
formats NewP (f1.0).
variable labels NewP 'Total Number of Placements'.
value labels NewP
1'2 Places or Less'
2'3 Places or More'
9'Missing'.
if (Los>0)served=1.
formats served (f1.0).
exe.

* Generate Table for State Data Profile Pt-in-Time Section XI.

TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total" $t000003 "Total"
  /TABLE=state + $t000001  BY los2 > ( newp + $t000003  )
  /STATISTICS
  count( newp( COMMA6.0 ) 'N')
  cpct( newp( PCT5.2 ) 'Subtable %':state los2 )
  count( $t000003( COMMA6.0 ) 'N')/Title 'FY98 Pt-in-Time Profile XI.'.


******************State Data Profile Pt-in-Time Section XII******************************************

*Of all children who entered care, what percentage re-entered foster care within 12 months
*of a prior foster care episode?

get file 'c:\cfsr\EZdata\EZEntry98C.sav'.
recode totalrem
(sysmis=9) (0=9) (1=1) (2 thru highest=2) into removals.
formats removals (f1.0).
recode dlstfcmo
(sysmis=99).
do if (removals=1 and dlstfcmo=99).
compute time=1.
else if (removals=2 and dlstfcmo=99).
compute time=9.
else if (removals=9).
compute time=9.
else if (removals=1 and dlstfcmo~=99).
compute time=9.
else if (removals=2 and dlstfcmo~=99).
compute time =(yrmoda(latremyr,latremmo,latremda)-yrmdoda(dlstfcyr,dlstfcmo,dlstfcda))/30.4375.
end if.
exe.
do if (removals=1 and dlstfcmo=99).
recode Time
(1=1) into TimeRE.
else if(removals=2 and dlstfcmo~=99).
recode Time
(252 thru highest=9) (12 thru 252=3) (.03 thru 12=2) (lowest thru .03=9) into TimeRE.
else.
recode Time
(9=9) into TimeRE.
end if.
value labels TimeRE
1'New Entry'
2'RE<12Months'
3'RE>=12Months'
9'Missing'.

TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total" $t000002 "Total"
  /TABLE=state + $t000001  BY timere + $t000002
  /STATISTICS
  count( timere( COMMA6.0 ) 'N')
  cpct( timere( PCT5.2 ) 'Row %':state )
  count( $t000002( COMMA6.0 ) 'N')/Title 'FY98 Pt-in-Time Profile XII.'.