*Thyne, Clayton *Intro to Stats, Chapter 11 examples clear set mem 80m cd [your directory] * NOTE: the above command asks you to change the directory. The directory will depend on how you've set up * the folders on your computer. For example, my command is... * cd F:\teaching\Fall_2008\PS572-401-baby_stats\do_file_directories\chapter11 * This is necessary so you know where stata is saving things. ****Part 1: examining the line of best fit use "http://www.uky.edu/~clthyn2/intro_stats/GPA-ACT.dta" *First, let's add some data for ACT gen ACT=. replace ACT = 28 in 1 replace ACT = 27 in 2 replace ACT = 26 in 3 replace ACT = 29 in 4 replace ACT = 24 in 5 replace ACT = 31 in 6 replace ACT = 25 in 7 replace ACT = 35 in 8 replace ACT = 25 in 9 replace ACT = 24 in 10 replace ACT = 26 in 11 replace ACT = 21 in 12 drop if ACT==. *Now, let's take a look at the data. NOTE: The Y axis should always *be the DV, which we always write first in stata. scatter GPA ACT *Now, add a line of 'best fit' graph twoway lfit GPA ACT || scatter GPA ACT graph twoway lfit GPA ACT || scatter GPA ACT, mlabel(school) ****Part 2: the OLS model example *Note: Minor differences are due to rounding errors regress GPA ACT *Note the significant P value for ACT (.000). *Stata is using the t table with 11 degrees of freedom. *Note the ANOVA table and significant F test for the model *Note R-squared and adjusted R-squared ****Part 3: examining regression further regress GPA ACT predict yhat scatter yhat ACT predict ehat, resid scatter ehat ACT gen observed=yhat+ehat ****Part 4: the lowess curve graph twoway lfit GPA ACT || scatter GPA ACT, saving(lfit, replace) graph twoway lowess GPA ACT || scatter GPA ACT, saving(lowess, replace) graph combine lfit.gph lowess.gph *As a better example, let's make one of observations an outlier replace ACT = 15 in 11 graph twoway lfit GPA ACT || scatter GPA ACT, saving(lfit, replace) graph twoway lowess GPA ACT || scatter GPA ACT, saving(lowess, replace) graph combine lfit.gph lowess.gph