# pwcorr_a **Repository Path**: arlionn/pwcorr_a ## Basic Information - **Project Name**: pwcorr_a - **Description**: stata command for pairwise correlation matrix - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 63 - **Forks**: 16 - **Created**: 2017-10-18 - **Last Updated**: 2026-03-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## pwcorr_a For details, see - 王若溪, 连玉君, 2020, [Stata结果输出:pwcorr_a输出相关系数矩阵](https://www.lianxh.cn/details/348.html), 连享会 No.348. The command `pwcorr_a` computes and displays the pairwise correlation coefficients for the variables listed in `varlist`. If `varlist` is not specified, it calculates the correlations for all variables in the dataset. The key distinction between `pwcorr_a` and Stata's official `pwcorr` command lies in their handling of significance levels. Specifically, `pwcorr_a` can simultaneously display `***` (indicating significance at the 1% level), `**` (significance at the 5% level), and `*` (significance at the 10% level). In contrast, the `pwcorr` command is limited to displaying only one significance level at a time. ## Install The installation files for `pwcorr_a` are stored on the [lianxh.cn](https://www.lianxh.cn) server and can be installed using the `cnssc` command. Therefore, you need to first install the `cnssc` command by running `ssc install cnssc`. The complete installation commands are as follows: ```stata ssc install cnssc, replace cnssc install pwcorr_a, replace ``` Then you can type `help pwcorr_a` to view the help ducoment, or check the version of `pwcorr_a`: ```Stata . which pwcorr_a D:/stata/plus\p\pwcorr_a.ado *! version 3.0.9 26Jan2025 ``` ## The difference between `pwcorr` and `pwcorr_a` ? The defult syntax of `pwcorr_a` is same as Stata's official command `pwcorr`: ```stata . sysuse auto, clear (1978 Automobile Data) . pwcorr price wei len mpg | price weight length mpg -------------+------------------------------------ price | 1.0000 weight | 0.5386 1.0000 length | 0.4318 0.9460 1.0000 mpg | -0.4686 -0.8072 -0.7958 1.0000 . pwcorr_a price wei len mpg | price weight length mpg -------------+------------------------------------ price | 1.000 weight | 0.539*** 1.000 length | 0.432*** 0.946*** 1.000 mpg | -0.469*** -0.807*** -0.796*** 1.000 ``` ## Customizing Significance Level Indicators By default, `pwcorr_a` uses `***`, `**`, and `*` to denote significance levels at the $1\%$, $5\%$, and $10\%$ thresholds, respectively. For example: ```stata . sysuse "nlsw88.dta", clear . local xx "wage hours ttl_exp age tenure" . pwcorr_a `xx' if 3.race | wage hours ttl_exp age tenure ---------+--------------------------------------------- wage | 1.000 hours | 0.415** 1.000 ttl_exp | 0.349* 0.467** 1.000 age | -0.461** -0.115 0.070 1.000 tenure | 0.236 0.219 0.571*** 0.203 1.000 ``` To customize the significance level indicators, you can use the **star#()** option. For instance, if you want to use `***`, `**`, and `*` to represent the $0.1\%$, $1\%$, and $5\%$ significance levels, respectively. Here is an example: ```stata . sysuse "nlsw88.dta", clear . local xx "wage hours ttl_exp age tenure" . pwcorr_a $xx if 3.race, /// star1(0.001) star5(0.01) star10(0.05) | wage hours ttl_exp age tenure ---------+--------------------------------------------- wage | 1.000 hours | 0.415* 1.000 ttl_exp | 0.349 0.467* 1.000 age | -0.461* -0.115 0.070 1.000 tenure | 0.236 0.219 0.571** 0.203 1.000 ``` ## Export to Word document You can use the `logout` command to export the correlation matrix generated by `pwcorr_a` to an Excel or Word document. The command is as follows: ```stata *-----Table 2: Correlation Matrix------- sysuse auto, clear local v "price wei len mpg" // Specify variables local s "Table2_corr" // file name logout, save("`s'") excel replace: /// pwcorr_a `v', format(%6.2f) //star(0.05) ``` This code snippet demonstrates how to save the correlation matrix for the specified variables (`price`, `weight`, `length`, and `mpg`) into an Excel file named `Table2_corr`. The `format(%6.2f)` option ensures the correlation coefficients are displayed with two decimal places. The `star(0.05)` option (commented out here) can be used to highlight significance levels if needed. ![20250126185414](https://fig-lianxh.oss-cn-shenzhen.aliyuncs.com/20250126185414.png)