To explore the effects of valproate on the selected outcomes, cause-specific Cox proportional hazard models censored for death were used with the valproate-specific genetic scores as independent variable, adjusted for age, sex, principal components (PC) 1–3, and genotyping assay in the cohort of valproate users. Although ischemic stroke subtypes are not available in the UKB, we tried to investigate the pathophysiological mechanism of valproate’s action on stroke prevention. To approximate cardioembolic stroke, ischemic stroke in the setting of atrial fibrillation was analyzed by adding an interaction term of the genetic score with prevalent atrial fibrillation in the model for ischemic stroke and performing subgroup analyses in individuals with and without a diagnosis of atrial fibrillation before or within six months after ischemic stroke. Because of the small cohort size, the main analyses were performed in all valproate users regardless of potential cryptic relatedness, and sensitivity analyses were performed in a cohort restricted to unrelated individuals (KING kinship coefficient < 0.0884). ChiSquare test for trend in proportions were used to assess significant differences in absolute stroke risk between genetic score tertiles. To rule out that observed associations between the genetic scores and the outcomes are caused by pleiotropic effects of the genetic score not related to valproate use, we tested the same associations among non-valproate users, thus assessing the independence and exclusion restriction assumptions of Mendelian randomization. To further rule out an antiepileptic drug class effect, all analyses were repeated with the genetic scores for lamotrigine and levetiracetam response among users of the respective drugs. To exclude drug interactions, we also performed a sensitivity analysis among the cohorts of patients on valproate monotherapy.