*! version 1.1.0 2026-05-11

Title

wavelet -- Wavelet analysis for time series: CWT, MODWT, XWT, WTC,
wavelet multiple correlation, wavelet multiple regression

Syntax

Main dispatcher:

wavelet subcommand [varlist] [, options]

Available subcommands:

lmodwt Maximal Overlap Discrete Wavelet Transform

wt Continuous Wavelet Transform (CWT)

xwt Cross-Wavelet Transform

wtc Wavelet Coherence (with Monte Carlo significance)

wmcorr Wavelet Multiple Correlation

wmreg Wavelet Multiple Regression

wmxcorr Wavelet Multiple Cross-Correlation

about Package information

filters List available wavelet filters

Or use commands directly:

lmodwt varname [if] [in],
[levels(#) filter(name) mra generate(prefix)]

wt varname [if] [in],
[dt(#) mother(name) param(#) dj(#) plot]

xwt var1 var2 [if] [in],
[dt(#) mother(name) param(#) dj(#)]

wtc var1 var2 [if] [in],
[dt(#) mother(name) nrands(#) plot]

wmcorr varlist [if] [in],
[levels(#) filter(name) level(#) plot]

wmreg varlist [if] [in],
[levels(#) filter(name) plot]

wmxcorr varlist [if] [in],
[levels(#) filter(name) maxlag(#) plot]

Description

wavelet (lwavelet) is a comprehensive wavelet analysis package for
Stata implementing both discrete and continuous wavelet transforms, bivariate
analysis (cross-wavelet, coherence), and multivariate frequency-band analysis
(multiple correlation, regression, cross-correlation).

The package provides tools for decomposing time series into frequency bands,
testing for co-movement between pairs of series across scales, and performing
regression analysis at different temporal resolutions. This is the first
complete wavelet analysis package for Stata, with functionality comparable to
R packages biwavelet, wavelets, and wavemulcor.

Installation

. ssc install lwavelet

The Mata library lwavelet.mlib ships pre-compiled with the package
and is loaded automatically by Stata on first use. The source files
_wv_*.mata and the build script _build_lwavelet.do are also
included for users who wish to rebuild from source.

Commands

Discrete Wavelet Transforms

lmodwt varname, levels(#) filter(name) [mra
generate(prefix)]

Computes the Maximal Overlap Discrete Wavelet Transform. The MODWT
decomposes a time series into frequency bands (wavelet scales) using a
non-decimated pyramid algorithm. Unlike the DWT, the MODWT preserves the
original sample size at each decomposition level.

levels(#) specifies the number of decomposition levels J. Default is 4.

filter(name) specifies the wavelet filter. Default is la8 (Least
Asymmetric, length 8). See wavelet filters for full list.

mra computes the Multiresolution Analysis, decomposing the signal into
J detail components (D1,...,DJ) and one smooth component (SJ).

generate(prefix) generates variables prefix_D1,...,prefix_DJ,
prefix_SJ containing the MRA components.

Continuous Wavelet Transforms

wt varname, [dt(#) mother(name) param(#)
dj(#) s0(#) siglvl(#) plot colormap(name)]

Computes the Continuous Wavelet Transform using the FFT convolution theorem.
Supports Morlet (default), Paul, and DOG mother wavelets.

dt(#) time step (default 1).

mother(name) mother wavelet: morlet (default), paul, or dog.

param(#) mother-specific parameter (default: k0=6 for Morlet, m=4 for
Paul, m=2 for DOG).

dj(#) scale spacing in sub-octaves (default 0.25 = 4 sub-octaves).

plot produces a time-frequency power spectrum heatmap.

colormap(name) colormap for plotting: jet, parula, or
turbo (default).

xwt var1 var2, [options same as wt]

Computes the Cross-Wavelet Transform: W_xy = W_x * conj(W_y). Identifies
common power and relative phase between two time series across scales.

wtc var1 var2, [nrands(#) plus options same as wt]

Computes Wavelet Coherence: R² = |S(W_xy)|² / (S(|W_x|²) * S(|W_y|²)).
Significance is tested via Monte Carlo simulation using AR(1) surrogates.

nrands(#) number of Monte Carlo surrogates (default 300).

Multivariate Wavelet Analysis

wmcorr varlist, [levels(#) filter(name)
level(#) plot]

Computes wavelet multiple correlation at each scale following
Fernandez-Macho (2012). At each scale j, the algorithm inverts the d×d
pairwise correlation matrix and computes R² = 1 - 1/max(diag(P^-1)).

level(#) confidence level for Fisher z-transform CI (default 0.95).

plot produces a scale-by-scale correlation plot with CI bands.

wmreg varlist, [levels(#) filter(name) plot]

Performs OLS regression at each wavelet scale. The dependent variable is
automatically selected as the variable yielding maximum R² (YmaxR).

wmxcorr varlist, [levels(#) filter(name)
maxlag(#) plot]

Computes wavelet multiple cross-correlation at each scale for lags
-maxlag to +maxlag, enabling lead-lag analysis across frequency bands.

Examples

A single coherent walkthrough using Stata's built-in Lütkepohl quarterly
macro dataset (1960q1–1982q4, log levels of investment, income, and
consumption). The full runnable script ships with the package as
example_lwavelet.do.

Setup

. webuse lutkepohl2, clear

. tsset qtr

1. MODWT decomposition of investment

With N=92 quarterly observations, J=3 is the maximum admissible level
for the LA(8) filter. The three detail bands cover periods of 6–12 months
(D1), 1–2 years (D2), and 2–4 years (D3); S3 captures everything slower
than ~4 years (trend + long cycle).

. lmodwt inv, levels(3) filter(la8) mra generate(_inv)

. matrix list e(wvar), format(%9.4f)

2. CWT power spectrum of investment

. wt inv, dt(0.25) mother(morlet) plot colormap(turbo)

3. Cross-wavelet transform inv–inc

. xwt inv inc, dt(0.25) mother(morlet)

4. Wavelet coherence with Monte Carlo significance and phase arrows

. wtc inv inc, dt(0.25) nrands(500) plot

5. Wavelet multiple correlation across inv, inc, consump

. wmcorr inv inc consump, levels(3) filter(la8) plot

. matrix list e(wmcorr), format(%9.4f)

. matrix list e(ymaxr)

6. Wavelet multiple regression (auto-selects dependent variable per scale)

. wmreg inv inc consump, levels(3) filter(la8) plot

. matrix list e(rsq), format(%9.4f)

7. Wavelet multiple cross-correlation (lead-lag, ±8 quarters)

. wmxcorr inv inc consump, levels(3) filter(la8) maxlag(8) plot

To run the entire example end-to-end with narrative comments and
interpretive notes, execute the bundled script:

. do example_lwavelet.do

Stored results

lmodwt

Scalars

e(N) number of observations

e(J) number of decomposition levels

Matrices

e(Wj) wavelet coefficients at level j (1 x N)

e(VJ) final-level scaling coefficients (1 x N) — named VJ because V is reserved by ereturn post

e(wvar) wavelet variance per level (J x 1)

wt

e(power) wavelet power spectrum (nscale x N)

e(period) Fourier period vector (nscale x 1)

e(scale) wavelet scale vector (nscale x 1)

e(coi) cone of influence (N x 1)

e(signif) significance levels (nscale x 1)

wmcorr

e(wmcorr) correlation, CI_low, CI_up (J x 3)

e(ymaxr) variable with max R² per scale (J x 1)

e(N_eff) effective sample size per scale (J x 1)

Methods and formulas

MODWT: The non-decimated pyramid algorithm applies the wavelet filter h
and scaling filter g at each level j with step size 2^(j-1) using circular
convolution:

W_j[t] = sum_^ h_l * V_[t - 2^ * l mod N]

V_j[t] = sum_^ g_l * V_[t - 2^ * l mod N]

CWT: Computed via the FFT convolution theorem. The signal is padded to
the next power of 2, transformed to frequency domain, multiplied by the
daughter wavelet at each scale, and inverse-transformed:

W(a,b) = IFFT[FFT(x) * Psi*(a*omega)]

Wavelet Multiple Correlation: At each scale j, compute the d×d pairwise
correlation matrix P from MODWT coefficients. Then:

R_j = sqrt(1 - 1/max(diag(P_j^{-1})))

CI: atanh(R) ± z_p / sqrt(n_j - 3), back-transformed via tanh().

Wavelet Coherence: Smoothed cross-spectrum divided by auto-spectra:

R²(s,t) = |S(s^{-1} W_xy)|² / [S(s^{-1} |W_x|²) * S(s^{-1} |W_y|²)]

Smoothing: Gaussian in time, boxcar (0.6/dj) in scale.

References

Fernandez-Macho, J. (2012). Wavelet multiple correlation and cross-correlation:
A multiscale analysis of Eurozone stock markets.
Physica A 391: 1097-1104.

Grinsted, A., Moore, J.C., Jevrejeva, S. (2004). Application of the cross
wavelet transform and wavelet coherence to geophysical time series.
Nonlinear Processes in Geophysics 11: 561-566.

Liu, Y., Liang, X.S., Weisberg, R.H. (2007). Rectification of the bias in
the wavelet power spectrum. J. Atmos. Oceanic Technol. 24: 2093-2102.

Percival, D.B., Walden, A.T. (2000). Wavelet Methods for Time Series
Analysis. Cambridge University Press.

Torrence, C., Compo, G.P. (1998). A practical guide to wavelet analysis.
Bull. Amer. Meteor. Soc. 79: 61-78.

Torrence, C., Webster, P.J. (1999). Interdecadal changes in the ENSO-
monsoon system. J. Climate 12: 2679-2690.

Veleda, D., Montagne, R., Araujo, M. (2012). Cross-wavelet bias corrected by
normalizing scales. J. Atmos. Oceanic Technol. 29: 1401-1408.

Author

Dr. Merwan Roudane

Email: merwanroudane920@gmail.com

Please cite as:

Roudane, M. (2026). lwavelet: Wavelet analysis for time series in Stata.
Statistical Software Components, Boston College Department of Economics.

Also see

Per-command help (click to open):

lmodwt MODWT decomposition (discrete)

wt Continuous wavelet transform

xwt Cross-wavelet transform

wtc Wavelet coherence + Monte Carlo

wmcorr Wavelet multiple correlation

wmreg Wavelet multiple regression

wmxcorr Wavelet multiple cross-correlation

Stata 18+ built-in: modwt (decimated DWT/MODWT — different from lmodwt).