Millions of students register for Massive Open Online Courses (MOOCs) seeking learning and self-development opportunities, but emotional experiences during the learning process can affect their participation and lead to dropout. This study quantifies this effect by applying the control-value theory to understand the role of achievement emotions comprehensively. A machine learning model was built and validated to automatically detect achievement emotions in forum posts. Survival analysis was then used to quantify the influence of these emotions on student dropout. The results reveal different mechanisms for how expressed and exposed achievement emotions affect student retention. The study discusses the implications for designing interventions to improve student retention in MOOCs.