version 11.0 log using Birth_Weight.LR.log, replace set more on * Birth_Weight.LR.log * * Linear regression of birth weight on estriol * See Rosner, Table 11.1, p554, and Green & Touchstone 1963 * set more on use rostab11.dta, clear regress bweight estriol predict y_hat, xb twoway scatter bweight estriol /// || line y_hat estriol /// , xlabel(10 (5) 25) xmtick(7 (1) 27) ytitle("Birth Weight (g/100)") more predict std_p, stdp generate ci_u = y_hat + invttail(_N-2,0.025)*std_p generate ci_l = y_hat - invttail(_N-2,0.025)*std_p twoway rarea ci_u ci_l estriol, color(gs14) /// || scatter bweight estriol /// || line y_hat estriol /// , xlabel(10 (5) 25) xmtick(7 (1) 27) ytitle("Birth Weight (g/100)") more * * Calculating values of expected birth weight with confidence intervals * associated with specific estriol levels that are in the dataset * list y_hat ci_u ci_l if estriol == 20 * * If the desired estriol level is not in the data set we procede as follows * set obs 32 replace estriol = 23 in 32 drop y_hat std_p ci_u ci_l predict y_hat, xb predict std_p, stdp generate ci_u = y_hat + invttail(_N-2,0.025)*std_p generate ci_l = y_hat - invttail(_N-2,0.025)*std_p list y_hat ci_u ci_l if estriol == 23 * The preceding graph could also have been generated without explicitly * calculationg yhat, ci_u or ci_l as follows * twoway lfitci bweight estriol /// || scatter bweight estriol /// , xlabel(10 (5) 25) xmtick(7 (1) 27) ytitle("Birth Weight (g/100)") more predict std_f, stdf generate ci_uf = y_hat + invttail(_N-2,0.025)*std_f generate ci_lf = y_hat - invttail(_N-2,0.025)*std_f twoway lfitci bweight estriol /// || scatter bweight estriol /// || rline ci_uf ci_lf estriol, color(red) /// , xlabel(10 (5) 25) xmtick(7 (1) 27) /// ylabel(20 (5) 45) ytitle("Birth Weight (g/100)") legend(off) more twoway scatter bweight estriol /// || lfit bweight estriol /// || lowess bweight estriol, bwidth(.8) /// ||, xlabel(10 (5) 25) xmtick(7 (1) 27) ytitle("Birth Weight (g/100)") more regress bweight estriol predict residual, rstudent twoway scatter residual estriol /// || lowess residual estriol /// , ylabel(-2 (1) 2) yline(-2 0 2) xlabel(10 (5) 25) xmtick(7 (1) 27) /// ytitle(Studentized residual) log close