/*---------------------------------------------------------------------------- corrprob -- correlations with p-values. STATA programs called: _ktau _spear Written by Sean Becketti, August 1990. ----------------------------------------------------------------------------*/ program define corrprob version 2.1 quietly { if ("%_*" == "") { di in bl "-> corrprob var1 var2 [if] [in] " /* */ " [, All Pearson Spearman Kendall]" exit } mac def _varlist "req ex min(2)" mac def _if "opt" mac def _in "opt" mac def _options "All Pearson Spearman Kendall" parse "%_*" mac def _spearma = "%_spearma"!="" | "%_all"!="" mac def _kendall = "%_kendall"!="" | "%_all"!="" mac def _pearson = "%_pearson"!="" | "%_all"!="" | /* */ !(%_spearma | %_kendall) parse "%_varlist", parse(" ") mac def _x "%_1" mac def _y "%_2" mac def _S_FN "%S_FN" mac def _CORR "_result(4)" /* from correlate */ save U_S_E_R, replace cap keep %_in cap keep %_if cap keep if %_x!=. & %_y!=. if (_N < 2) { di in re "Not enough observations," exit } di in gr "(nobs=" in ye =_N in gr ")" if (%_pearson) { corr %_x %_y mac def _pval = tprob(_N-2,%_CORR*sqrt((_N-2)/(1-%_CORR^2))) di in gr "Pearson's r = " in ye %5.2f = %_CORR di in gr "Prob z > |r| = " in ye %5.2f = %_pval } if (%_spearma) { _spear %_x %_y mac def _pval = tprob(_N-2,%_CORR*sqrt((_N-2)/(1-%_CORR^2))) di in gr "Spearman's r = " in ye %5.2f = %_CORR di in gr "Prob z > |r| = " in ye %5.2f = %_pval } if (%_kendall) { _ktau %_x %_y di in gr "Kendall's tau = " in ye %5.2f = %Result1 di in gr "Prob z > |tau| = " in ye %5.2f = %Result2 mac def Result1 mac def Result2 } use U_S_E_R, clear mac def S_FN "%_S_FN" erase U_S_E_R.dta } end