*! version 2.9 12Aug2025

Title

corrtex2 -- Export correlation matrix to publication-quality LaTeX table

Syntax

corrtex2
varlist
[if]
[in]
,
file(string)
[
digits(integer)
landscape
longtable
append
replace
casewise
placement(string)
title(string)
key(string)
na(string)
noscreen
nbobs
fontsize(string)
]

Description

corrtex2 exports a correlation matrix to a publication-quality LaTeX table with the following features:

- Automatically handles Chinese/English variable labels

- Adds significance stars (*** p<0.01, ** p<0.05, * p<0.10)

- Generates standalone LaTeX documents compilable with XeLaTeX

- Supports landscape orientation and longtable formats

- Includes observation counts with nbobs option

- Uses LaTeX dcolumn package for perfect decimal alignment

- Compatible with amsmath package for robust star formatting
- Supports by-group processing for subgroup analysis

Options

file(string) specifies the output LaTeX file (required).

digits(integer) sets decimal precision (default=3).

landscape formats table in landscape orientation.

longtable uses longtable environment for multi-page tables.

append/replace specifies file handling behavior.

casewise uses casewise deletion for correlations.

placement(string) sets LaTeX table placement (e.g., "htbp").

title(string) specifies custom table title.

key(string) sets LaTeX label prefix.

na(string) specifies missing value representation.

noscreen suppresses on-screen output.

nbobs displays observation counts below correlations.

fontsize(string) sets LaTeX font size (e.g., "\small", "\footnotesize").

Examples

Example 1: Basic usage with decimal alignment

. cd "E:\益友学术\鼎园会计130期\report"

. sysuse auto, clear

. corrtex2 price mpg weight length, file("mytable.tex") replace

Example 2: Chinese variables with advanced formatting

. use "E:\益友学术\鼎园会计130期\data\asure.dta", clear

. corrtex2 ESG NCSKEW DUVOL ret roa tobinq, ///

file("ESG_table.tex") replace ///

title("ESG相关性分析") ///

landscape longtable ///

fontsize("\small") ///

digits(4) nbobs

Example 3: Grouped correlations by ownership type (SOE vs non-SOE)

. bys soe: corrtex2 ESG NCSKEW DUVOL ret roa tobinq, ///

file("ESG_table2.tex") replace ///

title("ESG相关性分析") ///

landscape longtable ///

fontsize("\small") ///

digits(4) nbobs

Example 4: Custom formatting for large tables

. corrtex2 var1-var10, file("bigtable.tex") replace ///

digits(2) longtable landscape ///

fontsize("\footnotesize") nbobs

Authors

Wu Lianghai

Anhui University of Technology (AHUT)

Email: agd2010@yeah.net

Hu Fangfang

Wanjiang University of Technology (WJUT)

Email: huff470@163.com

Wu Hanyan

Nanjing University of Aeronautics and Astronautics (NUAA)

Email: 2325476320@qq.com

Zhao Xin

Anhui University of Technology (AHUT)

Email: 1980124145@qq.com

Acknowledgements

We sincerely thank Christopher F. Baum and Kit Baum for their guidance and selfless support.

Also see

correlate,
pwcorr,
corr2tex,
corrtex