clear all use table_75 gen age = A2_age drop *A1 *A2 *A3 *A4 *A5 *B1 *B2 *B3 *B4 *B5 // drop the few spells of length zero drop if tP == 0 | tZ == 0 // Table 1 gen col1 = 1 gen col2 = X_male gen col3 = 1-X_male gen col4 = (age<=25) gen col5 = (age>=55) matrix T1 = J(4,5,0) foreach cc of numlist 1(1)5{ qui su P if col`cc'==1 matrix T1[1,`cc'] = round(r(mean)*100,.1) qui su Z if col`cc'==1 matrix T1[2,`cc'] = round(r(mean)*100,.1) qui su Z if P==0 & col`cc'==1 matrix T1[3,`cc'] = round(r(mean)*100,.1) qui su Z if P==1 & col`cc'==1 matrix T1[4,`cc'] = round(r(mean)*100,.1) } matrix list T1 drop col* // Table 2 gen row1 = tP if P==1 gen row2 = tZ if Z==1 gen row3 = tZ if Z==1 & P==0 gen row4 = tZ if Z==1 & P==1 gen row5 = tZ-tP if Z==1 & P==1 gen row6 = tY gen row7 = tY if P==0 & Z==0 gen row8 = tY if P==1 & Z==0 gen row9 = tY if Z==1 & P==1 matrix T2 = J(9,6,0) foreach rr of numlist 1(1)9{ qui su row`rr' matrix T2[`rr',1] = round(r(mean),1) _pctile row`rr', p(10 25 50 75 90) foreach cc of numlist 1(1)5{ matrix T2[`rr',`cc'+1] = r(r`cc') } } matrix list T2