**Consistency & Necessity/Coverage Matrix
capture program drop suffnec
program define suffnec, rclass
version 9.0
syntax [anything] [fweight pweight iweight] [if] [, ALTDisplay USEREDuction LAST cluster(varname)]
local nument: word count `anything'
local namelist `anything'
if `nument'>2{
capture unab namelist: `anything'
}
marksample touse
unab vlist: _all

if "`last'"=="last" & "`r(colsig)'"=="" & "`r(comm)'"=="" {
	di as err `"Error: No "Last" Configuration Set Present"'
	di as err "Using Sets"
	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 indvars `namelist'
	local size: word count `indvars'
	matrix suffnec = J(`size',`size',0)
	local new "`indvars'"
	tokenize `new'

	local nonvar: list indvars - vlist
		foreach con of local nonvar {
			cnfgen `con'
		}
	unab indvars: `indvars'
}

foreach var of local indvars {
	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 sets "`r(sets)'"
	if "`usereduction'"=="usereduction" {
		local start `r(reducsols)'
		local sets `r(reducsols)'
		}
	local commsets `r(comm)'
	if "`last'" == "last"{
		if "`commsets'"=="" {
	 		local start `r(colsig)'
			local sets `r(colsig)'
			}
			else {
			local start `r(comm)'
	 		local sets `r(comm)'
			}
	}
	local y = r(y)
	if "`start'"=="." | "`start'"=="`sets'"{
		local start `sets'
		foreach con of local sets {
			cnfgen `con'
			}
	}
	local indvars: list y | start
	unab indvars: `indvars'
	local size: word count `indvars'
	matrix suffnec = J(`size',`size',0)
	local new "`indvars'"
	tokenize `new'
}

qui foreach var of local indvars {
	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 Matrix"
		local indvars: list indvars - toex
		local size: word count `indvars'
		matrix suffnec = J(`size',`size',0)
		local new "`indvars'"
		tokenize `new'
	}

di
di in white "{ul:Sufficiency and Necessity Matrix}"
   if "`altdisplay'" ~= "" {
	forvalues mx=`size'(-1)1 {
			local col "`col' ``mx''"
			}
	local z = `size'
	qui foreach var of local indvars {
		forvalues i = 1/ `size' {
			gen minvar = min(`var', ``i'')
			ratio (C: minvar / `var') if `touse' [`weight'`exp'] , cluster(`cluster')
			matrix suffnec[`z', `i'] = _b[C]
			drop minvar
			}
   	local z = `z' - 1
		}
	capture matrix colnames suffnec = "`indvars'"
	capture matrix rownames suffnec = "`col'"
	matlist suffnec, format(%9.3f)
	}
     if "`altdisplay'" == "" {
	local z = 1
	qui foreach var of local indvars {
		forvalues i = 1/ `size' {
			gen minvar = min(`var', ``i'')
			ratio (C: minvar / `var') if `touse' [`weight'`exp'] , cluster(`cluster')
			matrix suffnec[`z', `i'] = _b[C]
			drop minvar
			}
   	local z = `z' + 1
	}
	capture matrix colnames suffnec = "`indvars'"
	capture matrix rownames suffnec = "`indvars'"
	matlist suffnec, format(%9.3f)
	}

return local sets `sets'
return local y `y'
return local start `start'
return matrix suffnec=suffnec
capture keep `vlist'
end