help vardistinct

Title

vardistinct -- Generate a variable representing the number(s) of distinct observations or values

Syntax

vardistinct varlist [if] [in] , generate(newvar) [ by(varlist) missing ]

Description

The vardistinct command generates a new variable representing the number of distinct
observations or values with respect to the variables in varlist. Variables are considered jointly
so that newvar represents the number of distinct groups defined by the values of variabes in varlist.

By default, missing values are not counted. varlist may
contain both numeric and string variables.

Options

by(varlist) repeats the command on subsets of the data based on varlist.

missing specifies that missing values are to be included
in calculating the number of distinct observations.

Examples

. sysuse auto

. vardistinct rep78, generate(newvar)

. vardistinct rep78, generate(newvar) missing

. vardistinct rep78 foreign, generate(newvar)

. vardistinct rep78, by(foreign) generate(newvar)

. vardistinct rep78, by(foreign) generate(newvar) missing

Author

Harrison Garrett, hgarrett515@gmail.com

Acknowledgment

This program grew out of a response posted to Statalist by Nicholas J. Cox.