Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: _N in by-groups


From   Matthew White <mwhite@poverty-action.org>
To   statalist@hsphsun2.harvard.edu
Subject   st: _N in by-groups
Date   Fri, 19 Aug 2011 03:21:01 +0300

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. I'm writing a byable
program in which I want _N to be interpreted the former way, but I'm
having trouble; the default interpretation seems to be that _N is the
number of observations in the data set. I could do this:

program example, byable(recall)
marksample touse
preserve
qui keep if `touse'
[code...]
restore
end

But the preserve/keep would be slow with large data sets, right? Are
there better ways to do this?

Thank you,
Matt

-- 
Matthew White
Evaluation Coordinator
Urban Micro-Insurance Project
Innovations for Poverty Action

+254 (0)701 025 276
mwhite@poverty-action.org
*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index