-
Notifications
You must be signed in to change notification settings - Fork 0
/
corr_pval.ado
41 lines (39 loc) · 1.22 KB
/
corr_pval.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
capture program drop corr_pval
program define corr_pval, rclass
args adj
///////////////////////////////////////////////////////////////////////////////
// Description:
// ------------
// Computes the p-value from running corr or pwcorr. Useful for storing
// p-values for macros or tabulation. `adj' is 1 unless you are
// doing Bonferroni or Sidak corrections.
//
// Syntax:
// -------
// corr_pval
// MWE:
// ----
// sysuse auto
// pwcorr price trunk, sig
// corr_pval
// dis `r(corr_pval)'
// Remarks:
// --------
// . Code taken from underlying correlation command from ssc.
// . For some reason, the p-value is not available from return list.
// . See this:
// https://www.statalist.org/forums/forum/general-stata-discussion/general/4461-storing-p-value-of-corr-coeff-obtained-by-pwcorr
//////////////////////////////////////////////////////////////////////////////
if "`adj'"=="" local adj = 1
if (r(rho) != . & r(rho) < 1) {
local corr_pval=min(2*`adj'*ttail(r(N)-2,abs(r(rho))*sqrt(r(N)-2)/sqrt(1-r(rho)^2)),1)
}
else if (r(rho)>=1 & r(rho) != .) {
local corr_pval=0
}
else if r(rho) == . {
local corr_pval= .
}
// dis `corr_pval'
return local corr_pval `corr_pval'
end