************************************************************ *** *** Stata Statistics Workshop *** Createed by Mike Brown *** Last Edited: 6/10/16 *** ************************************************************ ******************Descriptive Statistics******************* *Import Stata data file use Entrance, clear *Summarize gpa sum gpa *Summarize gpa with details sum gpa, d *Obtain the mean of gpa mean gpa id age *Create a frequency table of gpa tab gpa *Create a two-way frequency table tab gender race *But this doesn't work with more than 2 tab gender race gpa *We must install an optional package 'fre' ssc install fre *Create a frequency table of gender fre gender gpa age *****Graphics***** *Create a histogram of gpa hist gpa help hist *Create a scatter plot of gpa and act scatter gpa act ******************Statistical Tests******************* *****t-tests***** help ttest *One-sample ttest gpa == 3.5 *Two-sample with groups ttest gpa, by(athlete) ttest gpa, by(race)//ERROR more than 2 groups found, only 2 allowed *Two-sample with vairables ttest age == gpa *One-sample with stats //ttesti #obs #mean #sd #val ttesti 500 3.5 .5 3.8 *Two sample with stats //ttesti #obs1 #mean1 #sd1 #obs2 #mean2 #sd2 ttesti 500 3.5 .5 300 3.53 .4 *****Anova***** *One-way ANOVA webuse census2.dta, clear oneway medage region //Bonferonni post-hoc test oneway medage region, b *****Correlations***** *Pearson pwcorr gpa act, sig star(.05) pwcorr gpa act age sat actsat, sig print(.05) *****Regression***** sysuse auto, clear *95% confidence interval regress price mpg headroom trunk weight length turn gear_ratio *Beta regress price mpg headroom trunk weight length turn gear_ratio, beta *Moderation regress price c.mpg##foreign headroom trunk weight length turn gear_ratio, beta