search for: max_fam

Displaying 1 result from an estimated 1 matches for "max_fam".

Did you mean: ai_fam
2005 Aug 01
6
converting stata's by syntax to R
...st one anyway, not caring which. Those observations are indicated above by keep==1. (Note, keep <- c(1,1,1,0,0,1,0) would be fine too, but not c(1,1,1,0,0,0,1)). The stata code I would use is bys fam (wt): keep if _n==_N This is my (long-winded) attempt in R: # first keep those rows where wt=max_fam(wt) maxwt <- by(dat,dat$fam,function(x) max(x[,2])) maxwt <- sapply(maxwt,"[[",1) maxwt.dat <- data.frame("maxwt"=maxwt,"fam"=as.integer(names(maxwt))) dat <- merge(dat,maxwt.dat) dat <- dat[dat$wt==dat$maxwt,] dat Now I am stuck - I want to keep either...