Hi,
Using the below current code, I could generate my desired output. That is the 95% credible interval for my variables of interests consiting of HLE_ ULE_ TLE_ PLE_. I would like to run this code by two additional variables (Age_Group and sort). I tried to include "by" option but got an error: sort may not be combined with by.
Thanks
Nader

*my current code
// keep the middle 950 values for each variable
local N_low = 26
local N_high =975

// keep track of the original order of the data
generate seq = _n

foreach v of varlist HLE_ ULE_ TLE_ PLE_ {
sort `v'
generate trim_`v' = `v'
replace trim_`v' = . if ! inrange(_n,`N_low',`N_high')
}

*what I tried
// keep the middle 950 values for each variable
local N_low = 26
local N_high =975

// keep track of the original order of the data
bysort Age_Group sort: generate seq = _n

foreach v of varlist HLE_ ULE_ TLE_ PLE_ {
bysort Age_Group sort: sort `v'
bysort Age_Group sort: generate trim_`v' = `v'
bysort Age_Group sort: replace trim_`v' = . if ! inrange(_n,`N_low',`N_high')
}