I have a dataframe with many firm-year observations and many variables.
Not all firms have information for all the years.
I want another dataframe with only those firms that have information all
years.
This is, I want a balanced panel data, but with the maximum number of years.
In my reprocucible example I want to keep firms 1,2 and 3 (period 2000 to
2004).
I need your help to create a code for this.
Thank you very much,
CecĂlia Carmo
(Universidade de Aveiro)
#My reproducible example:
firm<-sort(rep(1:3,5),decreasing=F)
year<-rep(2000:2004,3)
X<-rnorm(15)
data1<-data.frame(firm,year,X)
data1
firm<-sort(rep(4:6,3),decreasing=F)
year<-rep(2001:2003,3)
X<-rnorm(9)
data2<-data.frame(firm,year,X)
data2
finaldata<-rbind(data1,data2)
finaldata
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.