capture program drop conc
program conc,rclass
syntax varlist, comp(varlist) [tconc(real 0.4)]

di as result "{hline}"
di "{bf:Concurrent validity}"
di as result "{hline}"
di

local n : word count `varlist'
local p : word count `comp'

matrix m = J(`n',`p',.)
matrix rownames m = `varlist'
matrix colnames m = `comp'
local r = 1

foreach i in `varlist' {
	local c = 1
	foreach j in `comp' {
		qui corr `i' `j'
		mat e = r(C)
		local f = e[2,1]
		mat m[`r',`c'] = `f' 
		local `++c'
	}
	local `++r'
}

*mat li m, format(%3.2f) noheader

tokenize `varlist'
local maxv = length("`1'")
forvalues i=1/`n' {
	local lenv = length("``i''")
	if `lenv' > `maxv' local maxv = `lenv'
}

local decv = `maxv'+6

tokenize `comp'
local maxc = length("`1'")
forvalues i=1/`p' {
	local lenc = length("``i''")
	if `lenc' > `maxc' local maxc = `lenc'
}

local decc = `maxc'+4

local col = `decv'
foreach c in `comp' {
	di as result _col(`col') "`c'" _c
	local col = `col'+`decc'
}
di

local i = 1 
foreach x in `varlist' {
	local var`i' = "`x'"
	local `++i'
}


forvalues i=1/`n' {
	di as result "`var`i''" _c
	local col = `decv'
	forvalues j=1/`p' {
		local t = m[`i',`j']
		if `t' > `tconc' | `t' < -`tconc' {
			di as result _col(`=`col'-1') %5.2f `t' _c
		}
		else di as text _col(`=`col'-1') %5.2f `t' _c
		local col = `col'+`decc'
	}
	di
}

end

*conc HA-MOC, comp(ioc1 ioc2) tconc(0.4)
*conc x1-x40, comp(x1 x2) tconc(0.4)
