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)
* pctile 보다는 xtile을 쓰는 것이 좋겠다고 하고
* 새로운 변수에를 만들 때, _pctile 사용 추천한다고 함.
How to identify a variable's top/bottom 30% of each year in panel data? - Statalist
www.statalist.org
* loop 문으로 만들어야 한다고 생각하고 있었는데 그렇게 할 필요 없다고 함.
egen per70 = pctile(btm), p(70) by(year)
egen per30 = pctile(btm), p(30) by(year)
gen wanted = cond(btm <= per30, 1,
cond(btm <= per70, 2, 3)) if btm < .
그렇구나...