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   Seb Buechte <sfbuechte@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Counting the number of records in long format data
Date   Thu, 10 Nov 2005 10:57:23 +0100

Christer,

Your data looks like this?

lpnr     var1     var2
1         50        60
1         40        30
2         40        20
2         40        10
3         60        30
3         70        70
3         80        30
4         50        50


// are you looking for sth like this?
bysort lpnr: gen obs_count=_n


...Then your data looks like this...

lpnr     var1     var2     obs_count
1         50        60          1
1         40        30          2
2         40        20          1
2         40        10          2
3         60        30          1
3         70        70          2
3         80        30          3
4         50        50          1


Note: if you need to maintain a specific sort order you should specify
a sorting criteria to the  -bysort- like:

bysort lpnr (date_of_examination): gen obs_count=_n

This will number the observations in each group sorted by date of examination.

Kind regards,
sebastian

On 11/10/05, wying1@umbc.edu <wying1@umbc.edu> wrote:
> Try this?
>
> egen totobs = sum(1), by(lpnr)
>
>
> Ying
>
>
> > 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
> >
> > ***************************************
> > Professor Christer Thrane
> > Department of Social Science
> > Lillehammer University College
> > 2626 Lillehammer, Norway
> > + 47 61 28 81 70 (fax)
> > + 47 61 28 82 47 (phone, work)
> > + 47 61 25 53 04 (phone, home)
> > + 47 92 29 54 39 (mobile)
> >
> >
> > *
> > *   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/
> >
>
>
> Ying Wang
> Ph.D. Candidate
> Department of Public Policy
> University of Maryland, Baltimore County
> 1000 Hilltop Circle
> Baltimore, MD 21228
> Tel(O): 410-455-6531
> Tel(H): 410-747-6980
> Fax: 410-455-1172
> Email: wying1@umbc.edu
>
>
> *
> *   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/
>


--
- Seb F Buechte
-
- Stay tuned!

*
*   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