capt prog drop robust_gof
program define robust_gof, rclass
version 15
if "`e(cmd)'"!="sem" {
	di in red "This command only works after sem"
	exit 198
}
if "`e(vce)'"!="sbentler" {
	di in red "This command only works with sem,vce(sbentler) option"
	exit 198
}
* Satorra-Bentler-corrected statistics
local chi2_ms=`r(chi2_ms)'
local chi2_bs=`r(chi2_bs)'
local chi2sb_ms = `r(chi2sb_ms)'
local chi2sb_bs = `r(chi2sb_bs)'
local df_bs = `r(df_bs)'
local df_ms = `r(df_ms)'
local nobs=`e(N)'
local lb90_rmsea=`r(lb90_rmsea)'
local ub90_rmsea=`r(ub90_rmsea)'
* Calculation of Satorra-Bentler correction factor c_ms und c_bs
local c_ms = `e(sbc_ms)'
local c_bs = `e(sbc_bs)'
* Calculation of robust CFI, TLI, RMSEA
local cfi=`r(cfi)'
local tli=`r(tli)'
local cfi_sb=`r(cfi_sb)'
local tli_sb=`r(tli_sb)'
local rmsea=`r(rmsea)'
local rmsea_sb=`r(rmsea_sb)'
local robust_cfi = 1 - ((`c_ms' / `c_bs')*(1 - `cfi_sb'))
local robust_tli = 1 - ((`c_ms' / `c_bs')*(1 - `tli_sb'))
local robust_rmsea = sqrt(`c_ms')*`rmsea_sb'
*stores saved results in r()
return scalar robust_rmsea = `robust_rmsea'
return scalar robust_cfi = `robust_cfi'
return scalar robust_tli = `robust_tli'
* Display robust Fit indices
dis as text _n "Root-Mean-Squared-Error-of-Approximation: "
dis as text _n "MVN-based RMSEA = " as result %6.4f `rmsea'
dis as text "90% Confidence Interval for MNV-based RMSEA: "
dis as text "MVN-based Lower Bound (5%) = " as result %6.4f `lb90_rmsea'
dis as text "MVN-based Upper Bound (95%) = " as result %6.4f `ub90_rmsea'
dis as text _n "Satorra-Bentler corrected RMSEA = " as result %6.4f `rmsea_sb'
dis as text _n "Robust-RMSEA = " as result %6.4f `robust_rmsea'
* dis as text "90% Confidence Interval for robust RMSEA: "
* dis as text "Robust Lower Bound (5%) = " as result %6.4f `rob_rmsea_lb90'
* dis as text "Robust Upper Bound (95%) = " as result %6.4f `rob_rmsea_ub90' dis ""
dis as text _n "Incremental Fit-Indices: "
dis as text "MVN-based Tucker-Lewis-Index(TLI) = " as result %6.4f `tli'
dis as text "Satorra-Bentler corrected TLI = " as result %6.4f `tli_sb'
dis as text "Robust Tucker-Lewis-Index(TLI) = " as result %6.4f `robust_tli'
dis as text _n "MVN-based Comparative Fit Index (CFI) = " as result %6.4f `cfi'
dis as text "Satorra-Bentler-corrected CFI      = " as result %6.4f `cfi_sb'
dis as text "Robust Comparative Fit Index(CFI)  = " as result %6.4f `robust_cfi'
dis _n
end