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 ellegant solutions but you could do something like: test<-data.frame(year=c(2001,2001,2002,2001,2002,2003),id=c(1,2,2,3,3,3),x=runif(6)) test1<-aggregate(test,by=list(id=test$id),FUN=c("length","mean")) test2<-merge(test,test1[,c("id","x")],by.x="id",by.y="id") names(test2)<-c(names(test),"count") testsub<-subset(test2,count>2) testsub hth Stefan ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.