/*********************************************** * Kleinbaum, Chapter 6, Problem #4-6, p. 105 * ***********************************************/ /* Create the Stata dataset */ capture clear input person sbp quet age smk 1 135 2.876 45 0 2 122 3.251 41 0 3 130 3.100 49 0 4 148 3.768 52 0 5 146 2.979 54 1 6 129 2.790 47 1 7 162 3.668 60 1 8 160 3.612 48 1 9 144 2.368 44 1 10 180 4.637 64 1 11 166 3.877 59 1 12 138 4.032 51 1 13 152 4.116 64 0 14 138 3.673 56 0 15 140 3.562 54 1 16 134 2.998 50 1 17 145 3.360 49 1 18 142 3.024 46 1 19 135 3.171 57 0 20 142 3.401 56 0 21 150 3.628 56 1 22 144 3.751 58 0 23 137 3.296 53 0 24 132 3.210 50 0 25 149 3.301 54 1 26 132 3.017 48 1 27 120 2.789 43 0 28 126 2.956 43 1 29 161 3.800 63 0 30 170 4.132 63 1 31 152 3.962 62 0 32 164 4.010 65 0 end format quet %9.3f format smk %-9.0g label data "Klenbaum Chapter 5, Problem #2, p. 65" label variable person "ID" label variable sbp "Systolic Blood Pressure" label variable quet "Body Size" label variable age "Age" label variable smk "Smoker (0=no; 1=yes)" label define yesno 0 no 1 yes label values smk yesno list, noobs sep(11) quietly { corr quet age local alpha=0.01 local z=invnormal(1-(`alpha'/2)) local se=(r(N)-1)^.5 local rz=.5*(ln((1+`r(rho)')/(1-`r(rho)'))) local lb=`rz' - (`z'/`se') local ub=`rz' + (`z'/`se') local lb1 = (exp(2*`lb')-1)/(exp(2*`lb')+1) local ub1 = (exp(2*`ub')-1)/(exp(2*`ub')+1) #delimit ; noisily di _n "r_quet.age" _n _col(3) "r= " %4.3f r(rho) _col(12) "LB= " %4.3f `lb1' _col(23) "UB= " %4.3f `ub1' _col(34) "r2= " %4.3f r(rho)^2 _col(46) "n= " r(N); #delimit cr corr sbp age local alpha=0.01 local z=invnormal(1-(`alpha'/2)) local se=(r(N)-1)^.5 local rz=.5*(ln((1+`r(rho)')/(1-`r(rho)'))) local lb=`rz' - (`z'/`se') local ub=`rz' + (`z'/`se') local lb1 = (exp(2*`lb')-1)/(exp(2*`lb')+1) local ub1 = (exp(2*`ub')-1)/(exp(2*`ub')+1) #delimit ; noisily di _n "r_sbp.age" _n _col(3) "r= " %4.3f r(rho) _col(12) "LB= " %4.3f `lb1' _col(23) "UB= " %4.3f `ub1' _col(34) "r2= " %4.3f r(rho)^2 _col(46) "n= " r(N); #delimit cr corr sbp smk local alpha=0.01 local z=invnormal(1-(`alpha'/2)) local se=(r(N)-1)^.5 local rz=.5*(ln((1+`r(rho)')/(1-`r(rho)'))) local lb=`rz' - (`z'/`se') local ub=`rz' + (`z'/`se') local lb1 = (exp(2*`lb')-1)/(exp(2*`lb')+1) local ub1 = (exp(2*`ub')-1)/(exp(2*`ub')+1) #delimit ; noisily di _n "r_sbp.smk" _n _col(3) "r= " %4.3f r(rho) _col(12) "LB= " %4.3f `lb1' _col(23) "UB= " %4.3f `ub1' _col(34) "r2= " %4.3f r(rho)^2 _col(46) "n= " r(N); #delimit cr }