Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# st: RE: RE: selecting consecutive years, panel data

 From Nick Cox To "'statalist@hsphsun2.harvard.edu'" Subject st: RE: RE: selecting consecutive years, panel data Date Sun, 26 Sep 2010 17:03:37 +0100

```Assuming you have reduced each panel to consecutive runs, then

by firmid : drop if _N < 4

removes all panels less than 4 in length.

Nick
n.j.cox@durham.ac.uk

Martin Weiss

" And how do I count number of observations in panel data - for example
how many firms (the variable is defined as number) in total I have"

egen myfirms=group(firmid)
su myfirms, mean
di in red "Number of Firms: `r(max)'"

"...how many firms with currency CAD / USD I have in panel
(the currency is defined as string)?"

egen mytag=tag(firmid)
cou if mytag & currency=="CAD / USD "

Biljana Dlab

I have runs of consecutive observations (following instructions in FAQ,
bellow) - Now how do I drop runs of consecutive observations if the
number of consecutive observations is less than 4?

And how do I count number of observations in panel data - for example
how many firms (the variable is defined as number) in total I have in
the panel and how many firms with currency CAD / USD I have in panel
(the currency is defined as string)?

Nick Cox

This is an FAQ

FAQ     . . . . . . Identifying runs of consecutive observations in
panel data
. . . . . . . . . . . . . . . . . . . . . . . N. J. Cox and V.
Wiggins
8/02    How do I identify runs of consecutive observations
in panel data?
http://www.stata.com/support/faqs/data/panel.html

Martin Weiss

ssc d tsspell

by NJC may help.

Biljana Dlab

I have period from 1980-1995 and about 50 firms. For some firms
there is date for all year for other firms not.

Now I need to select those firm-years that are at least 4 consecutive
years long.

Any ideas and tips how to do that?

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