Mental disorders have a large impact on invalidity and mortality. Poor mental health is associated with low education, which is also associated with poor health and higher mortality. The association between mental health and mortality may, therefore, be partly explained by the increased incidence of mental problems of the low educated. An important issue is that mental health problems, education attainment and mortality may all depend on the same observed and unobserved individual factors. We account for both the selective incidence of mental health problems and selective educational attainment by using a correlated multistate model for the mental health (hospitalization) process (both admittance an discharge) and mortality with a re-weighting technique (inverse propensity weighting) based on the probability to attain higher education. We use Swedish Military Conscription Data (1951-1960), linked to the administrative Swedish death and National Hospital Discharge registers. We estimate the effect of mental hospitalization and education on the morality rate and how the effect of mental hospitalization is moderated by education. Our empirical results indicate a strong effect of both mental hospitalization and education on mortality. Mental hospitalization affects mortality due to external causes of death in particular. Only for the low educated improving education moderates the impact of mental hospitalization on mortality. We also found that ignoring onfounding would overestimate the impact of mental hospitalization on mortality. Accounting for confounding in mental hospitalization seems to be more important than accounting for selective educational attainment.