*! version 1.0.0 07Oct2025

Title

menger -- Menger curvature

Syntax

Using data with an ordered X variable and a continuous Y variable

menger
xvar
yvar
[if] [in]
[, graph detail]

Post-estimation after factor and pca

menger_estat
[, graph ]

detail display a table with the menger curvatures; available only for menger

graph graph of yvar on xvar with the maximum curvature (elbow) displayed

Description

menger computes the Menger curvature, which is a concept from geometry that measures
how "curved" a triplet of points is, based on the circle that passes through them (see the
wikipedia entry for greater detail). menger iterates
through each triplet of values in yvar and finds the curvature value. The maximum curvature point indicates
where the curve becomes more "flat" -- generally referred to as the "elbow" or "knee". menger_estat computes
the Menger curvature as a post-estimation command following factor and pca, as a means of finding an alternative number
of factors (components) to that used in Stata's official factor or "eye-balled" with screeplot.

Options

detail displays a table of each value of yvar and its corresponding curvature value. This allows
the user to see where the maximum curvature value is located, and its corresponding xvar value. detail
is only available for menger.

graph displays a graph of yvar on xvar with the maximum curvature (elbow) displayed. When specified
in menger_estat, the graph is identical to that implemented in screeplot.

Examples

(1) Compute Menger curvature from data

Setup (enter data directly into Stata)
. clear all
. input factor eigenvalue
1 1.08361
2 0.76609
3 0.22793
4 0.03324
5 0.01239
6 -0.00017
end

compute the Menger curvature, show the details of each computation and graph the results

. menger factor eigenvalue, detail graph

(2) Compute the Menger curvature after factor:

Setup
. use "https://www.stata-press.com/data/r19/sp2.dta", clear

perform a factor analysis

. factor ghp31- ghp05, ipf

find the "elbow" empirically using the menger curvature and display the results in a graph

. menger_estat, gr

Stored results

menger stores the following in r():

Scalars

r(elbow) the corresponding point on xvar where the maximum curvature is located

Matrix

r(results) matrix containing the xvars, yvars, and curvatures

menger_estat stores the following in r():

Scalar

r(elbow) the corresponding point on xvar where the maximum curvature is located

Citation of menger

menger is not an official Stata command. It is a free contribution
to the research community, like a paper. Please cite it as such:

Linden A. (2025). MENGER: Stata module to compute the Menger curvature.

Authors

Ariel Linden

President, Linden Consulting Group, LLC

alinden@lindenconsulting.org