**YAVYB**
capture program drop yavyb
program define yavyb, rclass
version 9.0
syntax [anything] [fweight pweight iweight] [if] [, group(varname) cluster(varname) SIGonly SLEVel(real .05) GREATer(namelist) USEREDuction LAST]
local nument: word count `anything'
local namelist `anything'
if `nument'>2{
capture unab namelist: `anything'
}
marksample touse
unab vlist: _all
local test "yavyb"
local oldgroup `r(oldgroup)'

if "`greater'" ~= "" {
	if "`greater'" ~= "col1" & "`greater'"~= "col2" {
		di as err `"Error: "`greater'" Not a Valid Option of Greater"'
		di as err "Greater Option Not Applied"
		local greater
	}
}

if "`oldgroup'"=="" & "`group'" == "" {
	di as error "ERROR: No Group Variable Defined"
	exit
	}

if "`oldgroup'"~="" & "`group'"=="" {
	di in red "Using `oldgroup' as Group Variable"
	local group `oldgroup'
	}

if "`last'"=="last" & "`r(colsig)'"=="" & "`r(comm)'"=="" {
	di as err `"Error: No "Last" Configuration Set Present"'
	di as err "Using Full Configuration Set"
	local last
}

if "`usereduction'"=="usereduction" & "`r(reducsols)'"=="" {
	di as err "Error: No Reduction Previously Performed"
	di as err "Can Not Use Reduced Solutions"
	capture keep `vlist'
	exit 119
}


if "`namelist'" ~= "" {
	local v `namelist'
	local y: word 1 of `v'
	local sets: list v - y
	  local nonvar: list v - vlist
        foreach con of local nonvar {
		cnfgen `con'
	  }
          unab sets: `sets'
}

foreach var of local sets {
	qui su `var'
	if `r(max)' > 1 | `r(min)'<0 {
		di as err "Error: `var' Not Fuzzified"
		capture keep `vlist'
		exit 119
	}
}

if "`namelist'" == "" {
	local start = r(start)
	local set "`r(sets)'"
	if "`usereduction'"=="usereduction" {
		local start `r(reducsols)'
		local set `r(reducsols)'
		}
	local commsets `r(comm)'
	if "`last'" == "last"{
		if "`commsets'"=="" {
	 		local set `r(colsig)'
			}
			else {
	 		local set `r(comm)'
			}
	}
	local y = r(y)
	capture myboolean `start'
		if _rc>0{
			local nonvar `set'
        		foreach con of local nonvar {
			cnfgen `con'
			}
		}
	unab sets: `set'
		mark nomis
		capture markout nomis `start'
		qui foreach var of local sets {
		capture replace `var'=. if nomis==0
		}
	qui drop nomis
}

qui tab `group'
	if `r(r)' ~=2 {
	di as err "Error: Group Variable Must Be 2 Categories"
	keep `vlist'
	exit
	}

qui ratio (`group'/`y'), over(`group')
local groups = e(over_labels)
local group1 : word 1 of `groups'
local group2 : word 2 of `groups'
local group1 : subinstr local group1 " " "", all
local group2 : subinstr local group2 " " "", all

qui foreach var of local sets {
	su `var'
	if `r(sum)' == 0 {
		local toex `toex' `var'
	}
}

local numexl: word count `toex'
	if `numexl'>0 {
		di
		di in green "Note: `toex' Have No Information and Excluded from Test"
		local sets: list sets - toex
	}
di
di in white "{ul:Y-Consistency for `group1' vs. Y-Consistency for `group2'}"
di as text %1s "Set", %12s "YCons`group1'", %10s "YCons`group2'", %4s "F", %9s "P"

foreach var of local sets {
  	tempvar num`var'
	qui gen `num`var'' = min(`y',`var')
     	qui ratio (Y:`num`var''/`var') if `touse' [`weight'`exp'] , over(`group', nolab) cluster(`cluster')
         	  local groups = e(over_labels)
		  local group1 : word 1 of `groups'
	        local group2 : word 2 of `groups'
	qui test _b[`group1'] = _b[`group2']
		if "`sigonly'" == "sigonly" {
	  		local p = r(p)
	  		if `p' < `slevel' {
			  if "`greater'"== "col1" {
				if _b[`group1']> _b[`group2'] {
			  		di as res %-6s "`var'", %9.3f _b[`group1'], %9.3f _b[`group2'], %9.2f r(F), %9.3f r(p)
			    		local `test'colsig "``test'colsig' `var'"
					}
			    		}
		  	if "`greater'" == "col2" {
				if _b[`group1'] < _b[`group2'] {
			  		di as res %-6s "`var'", %9.3f _b[`group1'], %9.3f _b[`group2'], %9.2f r(F), %9.3f r(p)
			 		local `test'colsig "``test'colsig' `var'"
					}
			    		}
			  if "`greater'" == "" {
				di as res %-6s "`var'", %9.3f _b[`group1'], %9.3f _b[`group2'], %9.2f r(F), %9.3f r(p)
				local `test'colsig "``test'colsig' `var'"
				}
				}
				}
 	else {
		  if "`greater'"== "col1" {
			if _b[`group1']> _b[`group2'] {
			  di as res %-6s "`var'", %9.3f _b[`group1'], %9.3f _b[`group2'], %9.2f r(F), %9.3f r(p)
			    local `test'colsig "``test'colsig' `var'"
			    }
			    }
		  if "`greater'" == "col2" {
			if _b[`group1'] < _b[`group2'] {
			  di as res %-6s "`var'", %9.3f _b[`group1'], %9.3f _b[`group2'], %9.2f r(F), %9.3f r(p)
			    local `test'colsig "``test'colsig' `var'"
			    }
			    }
		     if "`greater'" == "" {
			  di as res %-6s "`var'", %9.3f _b[`group1'], %9.3f _b[`group2'], %9.2f r(F), %9.3f r(p)
		 		local `test'colsig "``test'colsig' `var'"
				}
			      }
	  }

return local colsig ``test'colsig'
return local oldgroup `group'
return local start `start'
return local sets `sets'
return local y `y'
keep `vlist'
end