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
Related Posts with Question related to loop/foreach vvv
vlookup generates same idI read the thread on Complicated Vlookup-type problem in a large dataset. I am facing a similar pro…
When including interacted fixed effects, do I also have to include each fixed effects separately in the model?When including interacted fixed effects, do I also have to include each fixed effects separately in …
Cox model with an unbalanced panelHello everyone, I'm running a cox model with an unbalanced panel from 2015-2021 to measure the fact…
Difference in Difference analysis - how to create a group variableI think my question is pretty straightforward. I'd like to know what my "Group" is for a difference …
My Lorenz curves are coming out as straight lines.Hello Stata Experts, I am trying to create lorenz curves for a variable with four categories. I hav…
Subscribe to:
Post Comments (Atom)
0 Response to Question related to loop/foreach vvv
Post a Comment