Stata 15 help for _nobs


[P] _nobs -- Programmer's utility for counting the number of observations


_nobs varname [weight] [if exp] [in range] [, min(#) zeroweight ]

fweights, aweights, iweights, and pweights are allowed; see weights.


_nobs counts the number of observations based on a 0/1 variable giving the sample. (Strictly speaking, the variable is evaluated as 0/not 0.)

It is an rclass command, and the number of observations are returned in r(N).

If frequency weights (fweights) are specified, then the sum of the weights is used for the number of observations. If the weights are any other type, they are marked out, but otherwise ignored.

If the number of observations is less than those specified by the min() option, an appropriate error message is issued.


min(#) specifies the minimum allowed number of observations. If the number of observations is less than #, an error message is displayed. The default is min(1).

zeroweight specifies that weights of zero are not to be marked out.


_nobs is intended for use by programmers. Its typical use is the following:

program define myprog version ... syntax [varlist] [fweight iweight] [if] [in] marksample touse

_nobs `touse' [`weight'`exp'], min(2)

local N = r(N)

... end

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index