/* Set the random seed so we get the same random subsets */ set seed 200 /* Generate random number between 0/1 and put in "u" */ capture gen u=uniform() /* Create 10 equal size groups based on u If it already exists, do nothing */ capture xtile cat=u, nq(10) /* Create variable pred and make it missing. It will hold the predictions */ capture gen pred=. /* Cycle through numbers 1 to 10 Fit the logistic regression model for 90% of data Save predictions. Hold result for 10% of data not used for model */ forvalues k=1(1)10 { quietly logistic death if cat!=`k' quietly predict out`k' quietly replace pred=out`k' if cat==`k' } /* Examine the area under the ROC curve */ roctab death pred /* Housekeeping to reset variables so the do file can be re-run */ capture replace pred=. capture drop out*