Inpatient suicide and absconding of inpatients at risk of self-endangering behaviour are important challenges for all medical disciplines, particularly psychiatry. Patients at risk are often admitted to locked wards in psychiatric hospitals to prevent absconding, suicide attempts, and death by suicide. However, there is insufficient evidence that treatment on locked wards can effectively prevent these outcomes. We did this study to compare hospitals without locked wards and hospitals with locked wards and to establish whether hospital type has an effect on these outcomes. In this 15 year, naturalistic observational study, we examined 349 574 admissions to 21 German psychiatric inpatient hospitals from Jan 1, 1998, to Dec 31, 2012. We used propensity score matching to select 145 738 cases for an analysis, which allowed for causal inference on the effect of ward type (ie, locked, partly locked, open, and day clinic wards) and hospital type (ie, hospitals with and without locked wards) on suicide, suicide attempts, and absconding (with and without return), despite the absence of an experimental design. We used generalised linear mixed-effects models to analyse the data. In the 145 738 propensity score-matched cases, suicide (OR 1·326, 95% CI 0·803-2·113; p=0·24), suicide attempts (1·057, 0·787-1·412; p=0·71), and absconding with return (1·288, 0·874-1·929; p=0·21) and without return (1·090, 0·722-1·659; p=0·69) were not increased in hospitals with an open door policy. Compared with treatment on locked wards, treatment on open wards was associated with a decreased probability of suicide attempts (OR 0·658, 95% CI 0·504-0·864; p=0·003), absconding with return (0·629, 0·524-0·764; p<0·0001), and absconding without return (0·707, 0·546-0·925; p=0·01), but not completed suicide (0·823, 0·376-1·766; p=0·63). Locked doors might not be able to prevent suicide and absconding. None.