Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: _N in by-groups
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: _N in by-groups
Date
Fri, 19 Aug 2011 09:07:19 +0200
On Fri, Aug 19, 2011 at 2:21 AM, Matthew White wrote:
> If a Stata command has by-groups, it seems like _N is interpreted
> sometimes as the number of observations in the by-group and sometimes
> as the number of observations in the data set.
If you use the -by :- prefix it is always defined as the number of
observations within each by-group. Stata would be a pretty lousy
program if such a scalar randomly changed meaning...
If you want the total number of observations than I would just do:
local Ntot = _N
or inside a program that previously used -marksample-:
count if `touse'
local Ntot = r(N)
later you do
by <somevar> `touse' : <something using _N and `Ntot'> if `touse'
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/