[R] Drop firms in unbalanced panel if not more than 5 observations in consecutive years for all variables

2010-07-22 Thread Christian Schoder
Dear R-user, a few weeks ago I consulted the list-serve with a similar question. However, my task changed a little but sufficiently to get lost again. So I would appreciate any help on the following issue. I use the plm package and work with firm-level data in a panel. I would like to eliminate

Re: [R] Drop firms in unbalanced panel if not more than 5 observations in consecutive years for all variables

2010-07-22 Thread Stefan Grosse
Am 22.07.2010 11:18, schrieb Christian Schoder: I use the plm package and work with firm-level data in a panel. I would like to eliminate all firms that do not fulfill the requirement of having an observation in every variable used for at least x consecutive years. There are probably more

Re: [R] Drop firms in unbalanced panel if not more than 5 observations in consecutive years for all variables

2010-07-22 Thread Allan Engelhardt
One option: /## Your data:/ data - structure(list(id = structure(c(1L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c(a, b, c, d), class = factor), year = c(2000L, 2000L, 2001L, 1999L, 2000L, 2001L, 2002L, 1998L, 1999L, 2000L, 2001L, 2002L), y = c(1L, NA, 3L, 1L, 2L, 4L,

Re: [R] Drop firms in unbalanced panel if not more than 5 observations in consecutive years for all variables

2010-07-22 Thread Dimitris Rizopoulos
try this: Dat - read.table(textConnection( id year y z 1 a 2000 1 1 2 b 2000 NA 2 3 b 2001 3 3 4 c 1999 1 1 5 c 2000 2 2 6 c 2001 4 NA 7 c 2002 5 4 8 d 1998 6 5 9 d 1999 5 NA 10 d 2000 6 6 11 d 2001 7 7 12 d 2002 3 6 ), header = TRUE)

Re: [R] Drop firms in unbalanced panel if not more than 5 observations in consecutive years for all variables

2010-07-22 Thread Gabor Grothendieck
On Thu, Jul 22, 2010 at 5:18 AM, Christian Schoder schoc...@newschool.edu wrote: Dear R-user, a few weeks ago I consulted the list-serve with a similar question. However, my task changed a little but sufficiently to get lost again. So I would appreciate any help on the following issue. I