*! version 1.0.0 01Nov2023

Title

maxsum -- a function to compute the maximum value of a rolling-sum

Syntax

maxsum exp [if] [in] [, format(%fmt) ]

by is allowed with maxsum; see [D] by.

format(%fmt) display format for maxsum value; default format is %-14.2fc

Description

maxsum is a convenience tool for computing the maximum value of a rolling (cumulative) sum of an expression. It is intended to
offer Stata users a comparable solution to R's sum() function
or MS Excel's sum() function.

Examples

Setup

. sysuse auto, clear

Compute the maximum value of the rolling-sum for the variable weight, changing the format of the maxsum value produced

. maxsum weight, format(%-9.0f)

A more complex expression

. maxsum (price/mpg)^2

Using the [if] expression

. maxsum price if rep78 == 3

Using the by prefix

. bysort rep78: maxsum price

Stored results

maxsum stores the following in r():

Scalars

r(maxsum) the maximum value of the rolling-sum for an expression

Citation of maxsum

maxsum 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. (2023). MAXSUM: Stata module to compute the maximum value of a rolling-sum.
https://ideas.repec.org/c/boc/bocode/s459258.html

Authors

Ariel Linden

President, Linden Consulting Group, LLC

alinden@lindenconsulting.org

Also see

Online: sum(), egen total(), total