**[R] correlate** -- Correlations of variables

__Syntax__

Display correlation matrix or covariance matrix

__cor__**relate** [*varlist*] [*if*] [*in*] [*weight*] [**,** *correlate_options*]

Display all pairwise correlation coefficients

**pwcorr** [*varlist*] [*if*] [*in*] [*weight*] [**,** *pwcorr_options*]

*correlate_options* Description
-------------------------------------------------------------------------
Options
__m__**eans** display means, standard deviations, minimums, and
maximums with matrix
__nof__**ormat** ignore display format associated with variables
__c__**ovariance** display covariances
__w__**rap** allow wide matrices to wrap
-------------------------------------------------------------------------

*pwcorr_options* Description
-------------------------------------------------------------------------
Main
__o__**bs** print number of observations for each entry
**sig** print significance level for each entry
__list__**wise** use listwise deletion to handle missing values
__case__**wise** synonym for **listwise**
__p__**rint(***#***)** significance level for displaying coefficients
__st__**ar(***#***)** significance level for displaying with a star
__b__**onferroni** use Bonferroni-adjusted significance level
__sid__**ak** use Sidak-adjusted significance level
-------------------------------------------------------------------------

*varlist* may contain time-series operators; see tsvarlist.
**by** is allowed with **correlate** and **pwcorr**; see **[D] by**.
**aweight**s and **fweight**s are allowed; see weight.

__Menu__

__correlate__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Correlations and covariances**

__pwcorr__

**Statistics > Summaries, tables, and tests >** **Summary and descriptive**
**statistics > Pairwise correlations**

__Description__

The **correlate** command displays the correlation matrix or covariance
matrix for a group of variables. If *varlist* is not specified, the matrix
is displayed for all variables in the dataset.

**pwcorr** displays all the pairwise correlation coefficients between the
variables in *varlist* or, if *varlist* is not specified, all the variables
in the dataset.

__Options for correlate__

+---------+
----+ Options +----------------------------------------------------------

**means** displays summary statistics (means, standard deviations, minimums,
and maximums) with the matrix.

**noformat** displays the summary statistics requested by the **means** option in
**g** format, regardless of the display formats associated with the
variables.

**covariance** displays the covariances rather than the correlation
coefficients.

**wrap** requests that no action be taken on wide correlation matrices to
make them readable. It prevents Stata from breaking wide matrices
into pieces to enhance readability. You might want to specify this
option if you are displaying results in a window wider than 80
characters. Then you may need to **set linesize** to however many
characters you can display across a line; see **[R] log**.

__Options for pwcorr__

+------+
----+ Main +-------------------------------------------------------------

**obs** adds a line to each row of the matrix reporting the number of
observations used to calculate the correlation coefficient.

**sig** adds a line to each row of the matrix reporting the significance
level of each correlation coefficient.

**listwise** handles missing values through listwise deletion, meaning that
the entire observation is omitted from the estimation sample if any
of the variables in *varlist* is missing for that observation. By
default, **pwcorr** handles missing values by pairwise deletion; all
available observations are used to calculate each pairwise
correlation without regard to whether variables outside that pair are
missing.

**correlate** uses listwise deletion. Thus **listwise** allows users of
**pwcorr** to mimic **correlate**'s treatment of missing values while
retaining access to **pwcorr**'s features.

**casewise** is a synonym for **listwise**.

**print(***#***)** specifies the significance level of correlation coefficients to
be printed. Correlation coefficients with larger significance levels
are left blank in the matrix. Typing **pwcorr, print(.10)** would list
only correlation coefficients significant at the 10% level or better.

**star(***#***)** specifies the significance level of correlation coefficients to
be starred. Typing **pwcorr, star(.05)** would star all correlation
coefficients significant at the 5% level or better.

**bonferroni** makes the Bonferroni adjustment to calculated significance
levels. This option affects printed significance levels and the
**print()** and **star()** options. Thus **pwcorr, print(.05) bonferroni**
prints coefficients with Bonferroni-adjusted significance levels of
0.05 or less.

**sidak** makes the Sidak adjustment to calculated significance levels. This
option affects printed significance levels and the **print()** and **star()**
options. Thus **pwcorr, print(.05) sidak** prints coefficients with
Sidak-adjusted significance levels of 0.05 or less.

__Examples__

---------------------------------------------------------------------------
Setup
**. webuse census13**

Estimate correlation matrix
**. correlate mrgrate dvcrate medage**

Estimate covariance matrix; use population as analytic weight
**. correlate mrgrate dvcrate medage [aweight=pop], covariance**

---------------------------------------------------------------------------
Setup
**. sysuse auto**

Estimate all pairwise correlations
**. pwcorr price headroom mpg displacement**

Add significance level to each entry
**. pwcorr price headroom mpg displacement, sig**

Add stars to correlations significant at the 1% level after Bonferroni
adjustment
**. pwcorr price headroom mpg displacement, star(.01) bonferroni**

---------------------------------------------------------------------------

__Video example__

Pearson's correlation coefficient in Stata

__Stored results__

**correlate** stores the following in **r()**:

Scalars
**r(N)** number of observations
**r(rho)** rho (first and second variables)
**r(cov_12)** covariance (**covariance** only)
**r(Var_1)** variance of first variable (**covariance** only)
**r(Var_2)** variance of second variable (**covariance** only)
**r(sum_w)** sum of weights

Matrices
**r(C)** correlation or covariance matrix

**pwcorr** stores the following in **r()**:

Scalars
**r(N)** number of observations (first and second variables)
**r(rho)** rho (first and second variables)

Matrices
**r(C)** pairwise correlation matrix
**r(sig)** significance level of each correlation coefficient