program percentogram
version 16.0
syntax varlist(min=1 max=2), BINs(integer) *
local nb = `bins'+2
local vl : var label `varlist'
quietly {
  centile `varlist', centile(0(`=100/`bins'')100)
  tempname fr
  frame create `fr'
  frame `fr' {
    set obs `nb'
    gen x = .
    label var x "`vl'"
    forvalues i = 1/`=`nb'-1' {
      replace x = r(c_`i') in `i'
    }
    gen d = 1/((x - x[_n-1])*(`bins'))
    label var d "Density"
    replace d = 0 in 1
    replace d = 0 in `nb'
    replace x = x[_n-1] in `nb'
    line d x, connect(step) `options'
  }
}
end