* Variance.sps *. **************************************************************************************************** * * INSTITUTIONAL VARIANCE * Date : April 9, 1998 * by : Claude Delorme * Modified : May 11, 2000 * by : Sylvain Nadon * * This SPSS program computes variance estimates for the institutional component of the NPHS. The * program is an SPSS version of the existing SAS program created by Chris Mohl in March 1996. It * uses a two-stage sampling with replacement and the same algorithms as those used in the SAS * version. * Unlike in the case of the SAS version, the macro "Totals" is used for both computation of totals * and ratios. Up to 99,999 totals and 49,999 ratios can be calculated at any time. * * The directory 'C:\TEMP' must exist since it is used to store the following temporary files: * "labeltot", "labelrat", "person", "ninst", "ins", "str", "can" and "var". All of these files have * the "sav" extension and are erased after each run. * * The decimal point, and not the comma, must be used by the operating system as a way to separate * decimals; modify in "Control Panel" if needed. * * See "INSTRUCTIONS TO BE MODIFIED FOR EACH RUN" later in the proram. * **************************************************************************************************** set header=yes printback=no. title 'INSTITUTIONAL VARIANCE'. subtitle 'EXAMPLE FOR THE DOCUMENTATION OF THE 1996-97 PUMF FILE'. define !totals( var =!tokens(1) /dim =!tokens(1) /labfile=!tokens(1) /lstvar =!cmdend). !let !lstvrs=!concat('str1 to str',!dim). !let !lstvri=!concat('ins1 to ins',!dim). !let !lstvrc=!concat('can1 to can',!dim). !let !lstvrv=!concat('var1 to var',!var). !let !lstvrt=!concat('ter1 to ter',!var). * Sum of the weighted variables at the institution level, stratum level and Canada level. get file='c:\temp\person.sav'. weight by wti6wght. aggregate outfile='c:\temp\ins.sav' /presorted /break=canada stratum instno /!lstvri=sum(!lstvar). aggregate outfile='c:\temp\str.sav' /presorted /break=canada stratum /!lstvrs=sum(!lstvar). aggregate outfile='c:\temp\can.sav' /presorted /break=canada /!lstvrc=sum(!lstvar). get file='c:\temp\can.sav'. flip variables=!lstvrc. !if (!var~=!dim) !then compute den=var001. compute var001=lag(den,!var). execute. select if (not(sysmis(var001))). !ifend. save outfile='c:\temp\can.sav' /rename=(var001=can) /drop=case_lbl. * Computation of a term that acounts for the contribution to the variance for each institution. match files file='c:\temp\ins.sav' /table='c:\temp\str.sav' /table='c:\temp\ninst.sav' /by stratum. vector ins=!lstvri /str=!lstvrs. vector ter (!var). loop #i=1 to !var. compute ter(#i)=0. !if (!var~=!dim) !then compute #j=#i+!var. do if str(#j)>0. compute str(#i)=ninst*ins(#j)*str(#i)/str(#j). if ninst>1 ter(#i)=(((ins(#i)*ninst)-str(#i))**2)/(ninst*(ninst-1)). else. compute ter(#i)=0. end if. !else. if ninst>1 ter(#i)=(((ins(#i)*ninst)-str(#i))**2)/(ninst*(ninst-1)). !ifend. end loop. * Sum the variance terms up to the Canada level. aggregate outfile=* /presorted /break=canada /!lstvrv=sum(!lstvrt). erase file='c:\temp\ins.sav'. erase file='c:\temp\str.sav'. flip variables=!lstvrv. save outfile='c:\temp\var.sav' /drop=case_lbl /rename=(var001=var). * Output the total, variance and CV. match files file='c:\temp\can.sav' /file='c:\temp\var.sav' /file=!labfile. !if (!var~=!dim) !then do if den<=0. compute can=0. compute var=0. else. compute can=can/den. compute var=var/den**2. end if. !ifend. do if can=0. compute cv=0. else. compute cv=sqrt(var)/can*100. end if. * Print the results. do if $casenum=1. print eject. !if (!var=!dim) !then formats can var(F15.2) cv(F10.2). print eject /'DESCRIPTION' 13 'TOTAL' 84 'VARIANCE' 97 'CV' 114/. !else formats can(F15.5) var(F15.8) cv(F10.2). print eject /'DESCRIPTION' 13 'RATIO' 85 'VARIANCE' 97 'CV' 114/. !ifend. end if. print / ' ' label can var cv. execute. !enddefine. new file. input program. compute time=$time. print // '-----------------------------------------' / 'Date and time: ' time(datetime17) / '-----------------------------------------'//. end case. end file. end input program. execute. *--------------------------------------------------------------------------------------------------. * SPECIFICATIONS SECTION . * INSTRUCTIONS TO BE MODIFIED FOR EACH RUN . * SEE STEPS 1, 2 AND 3 . * . * Please make modifications only in the following section . *--------------------------------------------------------------------------------------------------. * STEP 2: * Assign a label (up to a maximum of 60 characters) to each variable that will appear on the output, * using a line per label. set printback=both. data list list /label (A60). begin data /* <<< LABELS FOR TOTALS <<< 'Total Population' 'Population 65 years old and older' 'Women 80 years old and older' end data. save outfile='c:\temp\labeltot.sav'. data list list /label (A60). begin data /* <<< LABELS FOR RATIOS <<< '65+ and close to staff members' '65+ and can conduct conversation in English only' '65+ and can conduct conversation in French only' '65+ and can conduct conversation in English and French only' end data. save outfile='c:\temp\labelrat.sav'. set printback=no. * ------------------------------------------------------------------------------------- END OF STEP 2. define !count(). !let !ntotal=0. !let !nrates=0. !let !dim=0. * -------------------------------------------------------------------------------------------------. * STEP 3: * Specify the number of totals and/or ratios, and the name of the directory where the files are stored. !let !ntotal=3. /* <<< NUMBER OF TOTALS <<< !let !nrates=4. /* <<< NUMBER OF RATIOS <<< !let !dim=8. /* <<< THIS NUMBER MUST BE EQUAL TO TWICE THE NUMBER OF RATIOS <<< !let !folder='N:\DEV\NADOSYL\INSTITUT\CYCLE2\VARIANCE\PUMF' /* <<< NAME OF THE DIRECTORY WHERE FILES ARE STORED <<< * ------------------------------------------------------------------------------------- END OF STEP 3. file handle datain /name=!quote(!concat(!folder,'/','inst.txt')). include file=!quote(!concat(!folder,'/','inst_in.sps')). do if $casenum=1 & !dim~=2*!nrates. print /// ' >>>>> >>>>> DIM = ' !quote(!dim) ' & NRATES = ' !quote(!nrates) ' <<<<< <<<<<' // ' >>>>> >>>>> ERROR: DIM MUST BE EQUAL TO TWICE THE VALUE OF NRATES <<<<< <<<<<' ///. end if. vector tot(!ntotal,F2). vector num den(!nrates,F2). * -------------------------------------------------------------------------------------------------. *STEP 1: * Define the variables that you want a variance for. * For totals, name the variables tot1-totn where n is the number of variables for which estimates are required. * Similarly for ratios, define num1-numm and den1-denm as the numerator and denominator of each of the m ratios. set mprint=no. /* <<< CREATION OF VARIABLES "TOT", "NUM" AND "DEN" <<< * Please refer to the data dictionary for values to be treated as missing. missing values dhi6gage ssi6g10 sdi6dlng(99). * Total Population. do if (wti6wght >0 ). compute tot1=1. else. compute tot1=0. end if. * Population 65 years old and older. recode dhi6gage (missing=sysmis) ( 1 thru 4 = 0) (5 thru 10 =1) into tot2. * Women 80 years old and older. do if (dhi6gage>=8 and dhi6_sex=2). compute tot3=1. else if (dhi6gage<=7 and dhi6_sex=2) or (dhi6_sex=1). compute tot3=0. end if. * Population 65 years old and older and close to staff members. do if (ssi6g10>0 and dhi6gage>=5). compute num1=1. else if (ssi6g10=0 or dhi6gage<5). compute num1=0. end if. * 65 years old and older and can conduct a conversation in English only. do if (sdi6dlng=1 and dhi6gage>=5). compute num2=1. else if (sdi6dlng>1 or dhi6gage<5). compute num2=0. end if. * 65 years old and older and can conduct a conversation in French only. do if (sdi6dlng=2 and dhi6gage>=5). compute num3=1. else if (sdi6dlng=1 or sdi6dlng>2) or (dhi6gage<5). compute num3=0. end if. * 65 years old and older and can conduct a conversation in English and French only. do if (sdi6dlng=3 and dhi6gage>=5). compute num4=1. else if (sdi6dlng<=2 or sdi6dlng>3) or (dhi6gage<5). compute num4=0. end if. * 65 years old and older. do if (dhi6gage>=5). loop #i=1 to !nrates. compute den(#i)=1. end loop. else if (dhi6gage<5). loop #i=1 to !nrates. compute den(#i)=0. end loop. end if. *----------------------------------------------------------------------------------------------------. * END OF SPECIFICATIONS <<< DO NOT MODIFY ANY TEXT OUTSIDE THE ABOVE SPECIFICATIONS SECTION <<<. *----------------------------------------------------------------------------------------------------. !let !lstvrt=''. !if (!ntotal>0) !then !let !lstvrt=!concat('tot1 to tot',!ntotal). !ifend. !let !lstvrr=''. !if (!nrates>0) !then !let !lstvrr=!concat('num1 to den',!nrates). !ifend. compute canada=1. formats canada(F1). save outfile='c:\temp\person.sav' /keep=stratum instno wti6wght !lstvrt !lstvrr canada. get file='c:\temp\person.sav'. sort cases by stratum instno. xsave outfile='c:\temp\person.sav'. * Count the number of institutions in each stratum. aggregate outfile=* /presorted /break=stratum instno /ninst=n. aggregate outfile='c:\temp\ninst.sav' /presorted /break=stratum /ninst=n. !if (!ntotal>0) !then !totals var=!ntotal dim=!ntotal labfile='c:\temp\labeltot.sav' lstvar=!lstvrt. execute. !ifend. !if (!nrates>0) !then !totals var=!nrates dim=!dim labfile='c:\temp\labelrat.sav' lstvar=!lstvrr. !ifend. new file. erase file='c:\temp\ninst.sav'. erase file='c:\temp\can.sav'. erase file='c:\temp\var.sav'. erase file='c:\temp\labeltot.sav'. erase file='c:\temp\labelrat.sav'. erase file='c:\temp\person.sav'. !enddefine. !count. set mprint=no.