Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Counting the number of records in long format data


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Counting the number of records in long format data
Date   Thu, 10 Nov 2005 07:53:33 -0500

Although egen sum() will get you what you want, it will do a bunch of work that you don't need it to. A more direct way, which is also noticeably faster in large datasets, is:

bysort lpnr: gen totobs=_N

Michael Blasnik
michael.blasnik@verizon.net

----- Original Message ----- From: <wying1@umbc.edu>

Try this?

egen totobs = sum(1), by(lpnr)

Hi,

I have a panel data set in long format. The identifying record variable is
called lpnr. Sometimes an observation occupies one row (that is, the
variables for this variable is only measured once), somtimes it occupies
two
rows (measured twice), sometimes three (measured three times) and so on.
However, I do not have a "time variable"--that is, a variable that counts
how many times (i.e. the number of rows) an observation appears? How can I
get this?

Best regards,

Christer
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index