https://stackoverflow.com/questions/15696107/stata-how-to-top-code-a-variable Stata: How to top-code a variable Using the auto.dta data, I want to top-code the PRICE variable at the median of top X%. For example, X% could be 3%, 4%, etc. How can I do this in Stata? stackoverflow.com sysuse auto, clear pctile pct = price, nq(10) dis r(r9) gen newprice=price replace newprice=r(r9) if newprice>r(r9..