Dear All,
Please can you help me with the following aim:
I want to obtain the mean, the percentile 2.5 and percentile 97.5 for the variable rmu_0 by values of w, x and y. I can achieve this with a loop as you can see below. However, the loop is really slow. It is particularly problematic because I want to do this for a series of variables.
to generate a mean of a variable by subgroups I can simply do the fast command:
However, how do I achieve this to obtain 2.5 and 97.5 percentile? it does seem that only _pctile command allows to obtain 2.5 and 97.5 percentile
This is my current slow code:
Thanks
A
Please can you help me with the following aim:
I want to obtain the mean, the percentile 2.5 and percentile 97.5 for the variable rmu_0 by values of w, x and y. I can achieve this with a loop as you can see below. However, the loop is really slow. It is particularly problematic because I want to do this for a series of variables.
to generate a mean of a variable by subgroups I can simply do the fast command:
Code:
bysort w x y: egen _mean_rmu_0=mean(rmu_0)
This is my current slow code:
Code:
gen _mean_rmu_0=.
gen _p1_rmu_0=.
gen _p2_rmu_0=.
foreach w in 0.3 0.5 0.70 {
foreach x in 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.7 2 {
foreach y in -20 -15 -10 -5 0 5 10 15 20 {
display "`x' & `y' & `w'"
cap sum rmu_0 if HAZARDRATIO==`x' & HRQOL_DIF==`y' & PFSRATECONTROL==`w'
cap replace _mean_rmu_0=`r(mean)' if HAZARDRATIO==`x' & HRQOL_DIF==`y' & PFSRATECONTROL==`w'
cap _pctile rmu_0 if HAZARDRATIO==`x' & HRQOL_DIF==`y' & PFSRATECONTROL==`w', percentiles(2.5)
cap replace _p1_rmu_0=`r(r1)' if HAZARDRATIO==`x' & HRQOL_DIF==`y' & PFSRATECONTROL==`w'
cap _pctile rmu_0 if HAZARDRATIO==`x' & HRQOL_DIF==`y' & PFSRATECONTROL==`w', percentiles(97.5)
cap replace _p2_rmu_0=`r(r1)' if HAZARDRATIO==`x' & HRQOL_DIF==`y' & PFSRATECONTROL==`w'
}
}
}
A

Comment