Hi Stata users,

I am trying to come up with percentile groups using the code below

Code:
_pctile asset_index, nquantiles(100)
return list
forval i=1/99 {
local p`i' = (r(r`i'))
}

gen percent = .
replace percent = 1 if asset_index < `p1'
replace percent = 100 if asset_index > `p99' & asset_index < .
forval i=1/98 {
di "``i''"
local j = `i' + 1
di "lower `p`i''"
di "upper `p`j''"
replace percent = `i' + 1 if inrange(asset_index, `p`i'', `p`j'')
}
ta percent
I am noticing that there are groups with extremely few number of observations such as 3 or 5. I am not sure whether the syntax is wrong or my understanding of how percentiles are calculated is misinformed.

Am attaching the dataset since
Code:
dataex
may not be the most effective way of sharing 9097 observations

Any advice is welcome.

Thanks in advance!