x cd /pub/data/acs2008/Tools; %let pgm=cpr_method_c17024; filename pgm "&pgm..sas"; *----Apply the CPR (county to PUMA ratio) method to estimate data for base table c17024 (age by poverty ratio). We use 2006-2008 period estimates data for estimating for the same period. J. Blodgett. 2/2010. ----*; %let acsyear=2008; *<---the acs vintage data year. The 2008 vintage data were released in 2009 and as of early 2010 are still the most current estimates.----; %let acsyr=%substr(&acsyear,3,2); %let acsyearm2=%eval(&Acsyear-2); %let acsyrm2=%substr(&acsyearm2,3,2); %let years=%str(&acsyearm2.-&acsyear); libname acsbtabs "/pub/data/acs&acsyear./basetbls"; libname acs2008 '/pub/data/acs2008' access=readonly; libname sf32000 "/pub/data/sf32000"; libname corrlst "/pub/data/corrlst"; libname cprdata '/pub/data/acs2008/cprdata'; libname temp '/pub/data/acs2008/cprdata/temp'; **filename cprmacs '/pub/data/acs2007/Tools/cprmacros.sas'; filename cprmacs '/pub/sasmacro/cprmacros.sas'; *<---this is new for this run, with new macro dodistp---; %include cprmacs ; *<--View the code at https://mcdc.missouri.edu/cgi-bin/browse?/pub/data/acs2007/Tools/cprmacros.sas@ --; %let debug=1; *--global variable referenced by at least 1 of the cpr macros (applycpr)---; options nosource; %macro dtastep; %*--Data step for processing the 2k (sf3) census data. Making it a macro so we can run it twice---; TotPop=pct16i1; _over18=pct25i1; Over65=pct25i35 + pct25i76; Age18_64=_over18-Over65; Under18=Totpop- _over18; _totpopck=sum(of under18 age18_64 Over65); if _totpopck ne totpop then do; put '**logic problems with age variables: ' _over18= totpop= age18_64= over65= _totpopck= ; abort abend; end; PovUTotal= pct50i1; PovUunder18=sum(of pct50i2 pct50i13 pct50i24 pct50i35 pct50i46 pct50i57); PovUage18_64=sum(of pct50i68 pct50i79 pct50i90 pct50i101 pct50i112); PovUover65=sum(of pct50i123 pct50i134); array _ageratio(3,5) Under18pr1-Under18pr5 Age18_64pr1-Age18_64pr5 Over65pr1-Over65pr5; array pct50(*) pct50i1-pct50i144; _p50i=2; do _agei=1 to 13; *--Table pct50 has 13 age cohort repeats but we group them into just 3 categories. These are reflected by the index variables _agei which ranges from 1 to 13 and _age3i which only ranges from 1 to 3.---; if _agei=1 then _age3i=1; else if _agei=7 then _age3i=2; else if _agei=12 then _age3i=3; if _agei in (1,7,12) then do; *--a new 3-level age grouping begins. Set the counts to 0---; do _povratioi=1 to 5; _ageratio(_age3i,_povratioi)=0; end; end; do _priin=0 to 10; if _priin=0 then goto nextcell; if _priin=1 then _pri=1; else if _priin <=3 then _pri=2; else if _priin =4 then _pri=3; else if _priin <=9 then _pri=4; else _pri=5; _ageratio(_age3i,_pri)= _ageratio(_age3i,_pri) + pct50(_p50i); ****temp diagnostic*******; _value_added= pct50(_p50i); *** if _n_=1 then put '**Add cell pct50i' _p50i ', Value=' _value_added comma9. ', to array with dims ' _age3i _pri ; ******end temp code****; nextcell: _p50i+1; end; end; *___agei loop--; %mend dtastep; /* =======================Begin comment================ proc sql; create table mocosinacs as select county as fipco from acs2008.usmcdcprofiles3yr where geoid like '05000US29%'; quit; data temp.clist; merge corrlst.mocnty_puma mocosinacs(in=inacs); by fipco; if inacs and pop2k > 64000 then delete; *--if we already have data then we do not need to estimate it--; *---but, for now, we leave in the medium size counties to see how our estimates compare with the data as reported in the ACS---; Sumlev='050'; Geocomp='00'; drop pop2k; run; options NOmprint; proc sort data=temp.clist; by sumlev county; run; *------------Step 1c: Access the data at the County level from 2k Census---; data temp.cen2kstate temp.cen2kcounty; merge sf32000.mophct(keep=_character_ pct50i: pct16i1 pct25i1 pct25i76 pct25i35 ) temp.clist(in=inclist); by sumlev county; where sumlev in('040','050') and geocomp='00'; **if not inclist then puma5='99999'; if inclist; %dtastep ; if _n_=1 then put / _all_; drop pct: _: ; if sumlev='050' then output temp.cen2kcounty; else output temp.cen2kstate; keep sumlev fipco county puma5 TotPop -- Over65pr5; run; proc sort data=temp.cen2kcounty ; by puma5; run; *---Step 1p: Repeat similar logic to get PUMA level summaries----; data temp.cen2kpumas; set sf32000.mopumasphct(in=inphct); by puma5; %dtastep; keep puma5 sumlev areaname TotPop -- Over65pr5; run; *------Step 2: Get PUMA and (some) county/state level data from the latest ACS tables. ---- *; *--NOTE that we do not ever use temp.acsstco since we are not doing any hlspt processing--*; data temp.acsstco(drop=puma5) temp.acspuma(drop=fipco county); length SumLev $3 fipco county $5 puma5 $5 ; set acsbtabs.ustabs17_203yr(keep=geoid areaname state c17024i: ); where state='29'; if substr(geoid,4,2)='00'; *--Missouri and a non-geocomp summary--; SumLev=substr(geoid,1,3); ***put geoid= areaname= sumlev= state= c17024i1=; if sumlev in ('795','050','040'); put geoid= areaname= sumlev= state= c17024i1=; PovUTotal=c17024i1; PovUunder18=c17024i2; PovUage18_64=c17024i11; PovUover65=c17024i20; *----The variables we save will not use the c17024iXXX naming convention. Instead we use the names below which are more mnemonic. We basically see it as 3 age-cohort-specific arrays of 5 pov-ratio cagegories.---; array _ageratio(3,5) Under18pr1-Under18pr5 Age18_64pr1-Age18_64pr5 Over65pr1-Over65pr5; array _c17024(3,0:8) c17024i2--c17024i28; do _iage=1 to 3; do _ipovr=1 to 4; *--Note that _ipovr=5 not included here. Assigned below--; _ageratio(_iage,_ipovr)=_c17024(_iage,_ipovr); end; end; _ageratio(1,5)=sum(of c17024i7-c17024i10); _ageratio(2,5)=sum(of c17024i16-c17024i19); _ageratio(3,5)=sum(of c17024i25-c17024i28); if sumlev='795' then puma5=substr(geoid,10,5); else if sumlev='040' then fipco=substr(geoid,8,2)||'000'; else fipco=substr(geoid,8,5); county=fipco; if sumlev='795' then output temp.acspuma; else output temp.acsstco; keep geoid sumlev fipco county puma5 PovUTotal--Over65pr5; run; proc print data=temp.acspuma; title2 "temp.acspuma"; run; proc sort data=temp.cen2kcounty; by puma5; run; ======================End comment================== */ options source; options mprint; *---Step 3: This is where we take all the data assembled in the first 2 steps and use it to approximate data for the smaller counties that are without any acs data yet. We use the cpr method by which we mean using county-to-puma ratios to estimate the indicators-; %genrenam(temp.cen2kpumas,xvars=_char_,sfx=_p2x,renamevar=rename_p2x) %put rename_p2x=&rename_p2x; %genrenam(temp.acspuma,xvars=_char_,sfx=_pacs,renamevar=rename_pacs) %put rename_pacs=&rename_pacs; %genrenam(temp.cen2kcounty,xvars=_char_,sfx=_c2x,renamevar=rename_c2x) %put rename_c2x=&rename_c2x; ***proc datasets library=cprdata; ***modify moagedata06_08; ***index create county; *** quit; *<====NOTE!!===; *------3.1: In this step we combine the cen2k data for ratios and the most recents acs puma data (3yr) to estimate the small county acs data (table c17024)---; data cprdata.c17024smallcounties&acsyr.3yr(label="Table c17024 data allocated to smaller counties using CPR methodology"); retain Years "&years" period '3yr'; merge temp.acspuma( &rename_pacs in=inpumas drop=geoid sumlev ) temp.cen2kcounty( &rename_c2x where=(puma5 ne ' ') in=incos ) temp.cen2kpumas ( &rename_p2x drop=SumLev areaname in=inpumas2k); by puma5; if incos; length fipco county $5; put puma5= county= inpumas= incos= inpumas2k=; if not (inpumas and inpumas2k) then abort abend; set cprdata.moagedata06_08 (keep=county TotPop Under18 over65) key=county; *---doing a custom estimation of the 4 universe totals here, taking advantage of the existence of 2008 pop estimates by age for all counties. Basic logic is to assume a consistent ratio of poverty universes to total pop in an age group. ---; _pctpovu=povutotal_c2x/totpop_c2x; PovUTotal=TotPop*_pctpovu; _pctpovuU18=PovUunder18_c2x/Under18_c2x; PovUunder18=_pctpovuU18*Under18; _pctpovu18_64=PovUage18_64_c2x/Age18_64_c2x; Age18_64=TotPop - Under18 - Over65; *<---was not explictly on cprdata.moagedataXXXXX---; PovUage18_64=_pctpovu18_64*Age18_64; _pctpovuOver65=PovUover65_c2x/Over65_c2x; PovUOver65=_pctpovuOver65*Over65; *--Comment out code originally used to do these 4 estimates--; %***applycpr(PovUTotal) ; *---Use the dodist macro to estimate the distribution table comprised of the 3 poverty universes by age, which sum to the PovUTotal--; %***dodist(PovU,sfxs=%str(under18 age18_64 over65),tabtot=PovUTotal) ; *---now we treat each of the 3 rows of the c17024 table as its own distribution and we estimate these---; %dodistp(Under18pr,%str(1 2 3 4 5),tabtot=PovUunder18) %dodistp(Age18_64pr,%str(1 2 3 4 5),tabtot=PovUage18_64) %dodistp(Over65pr,%str(1 2 3 4 5),tabtot=PovUOver65) format _numeric_ comma9. Pct: 5.1 _: best12.3 ; county=fipco; format county $mocnty.; SumLev='050'; geoid=sumlev||'00US'||fipco; if fipco='29001' then put / _all_; keep _character_ TotPop Under18 Age18_64 Over65 PovUTotal -- Over65pr5; drop _: ; run; proc sort ; by fipco; run; proc print data=&syslast (obs=5); title2 "&syslast"; run; *---combine ACS/cpr data w state & county (about 50 counties + state totals) to form a single dataset with all of it.--; data cprdata.c17024allcounties&acsyr.3yr; set temp.acsstco(in=inacs) cprdata.c17024smallcounties&acsyr.3yr; by fipco; *<---interleave---; if first.fipco; run;