Sample Code to Pool Multiple Cycles of CHIS Data

print share

Sample Code to Pool Multiple Cycles

The following SAS/SUDAAN and Stata codes show how to combine CHIS 2017 and 2018 data files and to create weights accounting for the multi-year files.

SAS/SUDAAN:

In addition to the sample code below, we also provide a SAS macro for user interested in analyzing CHIS data in SAS. This SAS macro will do all the work of weight adjustments automatically, and also generate other necessary information needed in later analysis. You can download this macro here: CHIS Pooling Macro


SAS:
data combined; /*this step concatenates the data files*/
	set libname.chis_2017 (in=in17) libname.chis_2018 (in=in18);
	
	if in17 then year=2017;
	else if in18 then year=2018;
	
	***Create new weight variables;
	fnwgt0 = rakedw0/2;
	array a_origwgts[80] rakedw1-rakedw80;
	array a_newwgts[160] fnwgt1-fnwgt160;
	do i = 1 to 80;
		if year=2017 then do;
			a_newwgts[i] = a_origwgts[i]/2;
			a_newwgts[i+80] = rakedw0/2;
		end;
		else if year=2018 then do;
			a_newwgts[i]    = rakedw0/2;
			a_newwgts[i+80] = a_origwgts[i]/2;
		end;

	end;
run;

proc surveyfreq data = combined varmethod=jackknife;
	weight fnwgt0;
	repweight fnwgt1-fnwgt160/jkcoefs=1;
	table ins;
run;


a Jackknife coefficients are necessary for accurate variance calculaDons, and jackknife coefficients of 1 in SAS will produce equal variance calculaDons as those produced in SUDAAN. However, for SAS V.9.2(TS1M0) and earlier, a value of 1 will not be accepted; as a subsDtute, 0.9999 can be entered. Without this specificaDon, the default value of the jackknife coefficients will be [(# replicate weights - 1)/# replicate weights]; for CHIS, this would be [(80 - 1)/80] = 0.9875.

Stata:


log using "folder location\data_step.log", replace
***CHIS 2017 Adult data****
use "your folder location\CHIS 2017 data"

gen year=2017

gen fnwgt0=rakedw0/2

for new fnwgt1-fnwgt160: gen X=0

foreach i of numlist 1/80{
            local j=`i'-0
            replace fnwgt`i'=rakedw`j'/2

}

foreach i of numlist 81/160{
            replace fnwgt`i'=rakedw0/2

}

save adult17 , replace

***CHIS 2018 Adult data****
use "folder location\CHIS 2018 data"

gen year=2018

gen fnwgt0=rakedw0/2

for new fnwgt1-fnwgt160: gen X=0

foreach i of numlist 1/80{           
            replace fnwgt`i'=rakedw0/2

}

foreach i of numlist 81/160{
            local j=`i'-80
            replace fnwgt`i'=rakedw`j'/2
}

append using adult17 /*this step concatenates the data files*/
save "folder location\combined.dta", replace

svyset [pw=fnwgt0], jkrw(fnwgt1-fnwgt160, multiplier(1)) vce(jack) mse


The above SAS and Stata code illustrate how to extract stored esDmates from SAS procedures and Stata commands and perform data operaDons based on the saved data.

For SAS, ODS OUTPUT statement saves the outputs from SAS procedures to a working dataset. ODS OUTPUT ONEWAY is used for one-way table, and ODS OUTPUT CROSSTABS is used for two-way crosstabs.

In this example, results are saved in the EST_COMBINED data, users may choose to use PROC PRINT to display the results in ODS window, or use PROC EXPORT to output them to an Excel file.

For Stata, returned Stata results are saved to Stata scalars and can be accessed later. Aeer generaDng results from both years, users may choose to either use DISPLAY command to outputs these scalars in results window or use PUTEXCEL to save the results to an Excel file.

General Formula for Pooling

The above code example shows how to pool esDmates from 2 CHIS year.The general pooling should follow formula: