在stata中,对几个变量进行相关性矩阵的分析,主要有correlate和pwcorr两个函数。
correlate显示一组变量的相关矩阵或协方差矩阵。如果不指定varlist,则显示数据集中所有变量的矩阵。
pwcorr显示varlist中变量之间的所有成对相关系数,如果未指定varlist,则显示数据集中的所有变量。
几行简单的代码:
Correlation matrix for variables v1, v2, and v3
correlate v1 v2 v3
Same as above, but display covariances instead of correlations
correlate v1 v2 v3, covariance
Pairwise correlation coefficients between v1, v2, and v3
pwcorr v1 v2 v3
Also print significance level of each correlation coefficient
pwcorr v1 v2 v3, sig
Same as above, but star correlation coefficients significant at the 5% level
pwcorr v1 v2 v3, sig star(.05)
Same as above, but use Bonferroni-adjusted significance levels
pwcorr v1 v2 v3, sig star(.05) bonferroni