Good afternoon,
I do not understand how the code from -egen, pctile- works. Can somebody explain what does the portion of code in green do?
I cannot relate this code in no way to the description in the Methods and Formulas in -pctile-.
I do not understand how the code from -egen, pctile- works. Can somebody explain what does the portion of code in green do?
Code:
mark `touse' `if' `in'
gen double `x' = `exp' if `touse'
sort `touse' `by' `x'
tempvar N
by `touse' `by': gen long `N' = sum(`x'!=.)
local rj "round(`N'[_N]*`p'/100,1)"
#delimit ;
by `touse' `by': gen `typlist' `varlist' =
cond(100*`rj'==`N'[_N]*`p',
(`x'[`rj']+`x'[`rj'+1])/2,
`x'[int(`N'[_N]*`p'/100)+1]) if `touse' ;
#delimit cr
Comment