Variables affecting length of psychiatric inpatient treatment