Hi,
Using the below sample data, I am trying to obtain the number of values in b1 (id=50_512) that exceed the maximum value of b1 when id=50_511. I would like to do same thing for b2. Given that I have 65 ids in my real data, I was wondering if there is any way to obtain my info of interest using a loop.
Thanks,
Nader




[QUOTE]
clear
// generate example data
set obs 15
set seed 666
gen n=_n
generate b1 = runiform(0,1)
generate b2 = runiform(-50,50)
gen Age_Group=""
replace Age_Group="50_51" if n<6
replace Age_Group="50_51" if n>5 & n<11
replace Age_Group="50_51" if n>10

gen sample_label=.
replace sample_label=1 if n<6
replace sample_label=2 if n>5 & n<11
replace sample_label=3 if n>10
label define sample_label 1 "1.NCG" 2 "2.caregivers<14h/w" 3 "3.caregivers>=14h/w"
label values sample sample

*id is the combination of Age_Group and sample_label
gen id=""
replace id="50_511" if n<6
replace id="50_512" if n>5 & n<11
replace id="50_513" if n>10