clear clear matrix set more off, perm cap log close cd "...\DAC555555 - Doe\Data" //client data folder sysdir set PERSONAL "StataDirectory" //wherever your stata directory is log using "...\DAC555555 - Doe\Output\202410\20241009\DAC555555_20241009_analysis.log", replace //example using John Doe, October 9th 2024 //NOTE: The following template only works with CHIS years 2011 onwards. Any pooling involving previous years must be done manually to account for CHIS design in those years local ages ADULT TEEN CHILD //replace with the age groups you want pooled, always follow order ADULT-TEEN-CHILD if applicable local agecount : word count `ages' local years 2019 2020 2021 2022 //replace with the years you want to pool together - 2011 onwards are valid. Only use single-years local yearcount : word count `years' local total_fnwgt = `yearcount' * 80 //number of final fnwgt replicate weights in pooled data quietly{ //suppress spamming of console foreach age of local ages{ //Pooling for each age group forval yearcounter = 1/`yearcount' { local year : word `yearcounter' of `years' //initialize year to be current year use `age'_`year', clear //read in current year of data rename *, lower //rename all variables to lower case gen fnwgt0 = rakedw0 / `yearcount' // new base weight = old base weight divided by number of years forval rep = 1/80 { local fnwgt_index = (`yearcounter' - 1) * 80 + `rep' //example: year 0 has fnwgt index values of 1-80, year 3 has index values of 161-240, etc if `yearcounter' == 1 { gen fnwgt`fnwgt_index' = rakedw`rep' / `yearcount' //example: first year fnwgt7 corresponds to rakedw7 } else { if `rep' <= 80 { gen fnwgt`fnwgt_index' = rakedw`rep' / `yearcount' //example: third year fnwgt185 corresponds to rakedw25 } } } forval j = 1/`total_fnwgt' { if !inrange(`j', (`yearcounter' - 1) * 80 + 1, `yearcounter' * 80) { //all fnwgt not based off of rakedw1-rakedw80 should be based off of rakedw0 instead gen fnwgt`j' = rakedw0 //base weight already divided by number of years above, no need to redo } } gen year = word("`years'", `yearcounter') //gen a year variable gen atc = "`age'" //gen an "atc" variable, can be "ADULT"/"TEEN"/"CHILD" sort baseid //sort by baseid for proper merging save `age'_pool_`year'.dta, replace } } foreach age of local ages{ use `age'_pool_`=word("`years'",1)', clear forvalues yearcounter=2/`yearcount' { //append other years to the first year local year = word("`years'", `yearcounter') append using `age'_pool_`year' sort baseid save `age'_pooled_all.dta, replace } } } //end quietly statement - re-enable console output //how to merge the age groups should be decided based upon the needs of an individual researcher use ADULT_pooled_all.dta //whichever dataset you want to use for analysis, can be single age group pooled or merged age groups svyset [pw=fnwgt0], jkrw(fnwgt1-fnwgt`total_fnwgt', multiplier(1)) vce(jack) mse //apply new pooled replicate weights //insert analysis here log close //final line of program