*! version 0.2.0 13mar2022

Title

cv2 -- Stata module to calculate the coefficient of variation for variables

Syntax

cv2
varlist
[if]
[in]
[, warn(warning_level) onlynomiss]

warn specifies below which value of the absolute mean warnings should be issued; if none is specified, cv2 will assume .05

onlynomiss instructs cv2 to only consider observations that have no missing values in any of the variables listed in varlist

Description

cv2 automates the trivial task of calculating the coefficient of variation (CV) for each of a given list of variables.

The CV (infrequently also referred to as the coefficient of relative variation, CRV) is a measure of dispersion of a variable. It is defined as the variable's standard deviation divided by the mean. The CV is independent of the units of measurement and of the magnitude of the data. Consequently, it can be used to compare the variability of different variables. Of two variables, the variable with the smaller CV is less dispersed than the variable with the larger CV.

Please note that the CV is only meaningful for ratio variables, i.e., variables for which zero indicates the complete absence of the measured quantity. Temperature measured in degrees Celsius, for instance, is not such a variable because zero degrees Celsius does not imply the absence of temperature. A unit that would yield an interpretable CV would be degrees Kelvin, with zero indicating complete absence of temperature.

Please note that the CV is not defined for cases in which the mean is zero. The CV also takes on extreme values when the mean becomes very small. cv2 will therefore issue warnings in such cases. Please also note that the CV will become negative if the mean value is negative. Again, cv2 will issue a warning.

cv2 can be used with by:

. by my_group_id: cv2 var1 var2

Examples

Simple example for three variables, with user-specified warning threshold

. webuse rvary2

. cv2 rater1 rater2 rater3, warn(.10)

References

Abdi, H. (2010). Coefficient of Variation. In N. J. Salkind (Ed.), Encyclopedia of Research Design, Vol. 1 (pp. 169-171), Thousand Oaks, CA: SAGE Publications.

Allison, P. D. (1978). Measures of Inequality. American Sociological Review, 43(6), 169-171.

Author

Lorenz Graf-Vlachy

graf-vlachy.com

mail@graf-vlachy.com