Advertisement
aidanhorn

Stata: kernel density with median line

Apr 2nd, 2020
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. * Kernel density plot
  2.  
  3. * realearnings base month is December 2016.
  4. gen earnings202002 = realearnings/100*115.2
  5. * now the base month is February 2020.
  6. gen learnings202002 = asinh(earnings202002)
  7. label variable learnings202002 "Monthly earnings (Feb 2020 rands)"
  8.  
  9. * use bracketweight for earnings analysis (see the PALMS User Guide)
  10.  
  11. capture kdens
  12. if _rc == 199 {
  13. ssc install moremata
  14. ssc install kdens
  15. }
  16.  
  17. summ earnings202002 [aw=bracketweight], detail
  18. scalar MEDIAN = round(r(p50))
  19. scalar lMEDIAN = log(MEDIAN)
  20. scalar TOTALMEAN = round(r(mean))
  21. scalar lTOTMEAN = log(TOTALMEAN)
  22. kdens learnings202002 if earnings202002 > 40 & earnings202002 < 300000 [pw=bracketweight], ci name("total", replace) xline(`=scalar(lTOTMEAN)', lc(lime) lp(dash)) xline(`=scalar(lMEDIAN)', lc(blue)) note("Dashed light-green line shows mean monthly earnings (R`=scalar(TOTALMEAN)')." "Solid blue line shows median monthly earnings (R`=scalar(MEDIAN)')." "Source: QLFS 2017 Q4") xlabel(4.605 "100" 6.908 "1 000" 9.21 "10 000" 11.513 "100 000") scale(1.1) title("Total earnings distribution in SA (2017 Q4)") // -kdens- uses the optimal bandwidth, and can generate the confidence intervals automatically
  23. graph export "QLFS2017Q4 total earnings distribution.pdf", replace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement