Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 auto.dta 数据,我想在顶部 X% 的中位数处对 PRICE 变量进行顶部编码。例如,X% 可能是 3%、4% 等。我如何在 Stata 中做到这一点?
在回答您的问题时,我假设您要替换上面的所有值,比如 top 10%,用值 say X(top 90%在下面的代码中)。
10%
X
top 90%
这是示例代码:
program topcode sysuse auto, clear pctile pct = price, nq(10) dis r(r9) gen newprice=price replace newprice=r(r9) if newprice>r(r9) end