version 19.5 **# Load and explore data *Load the built-in auto.dta example dataset. sysuse auto *Compute basic summary statistics for all variables in the current dataset. summarize **# Basic graphs *Create a histogram of mpg overlaid with a normal density curve. histogram mpg, normal *Create a scatterplot of price versus mpg overlaid with a line showing their linear relationship. twoway (scatter price mpg) (lfit price mpg) **# Association *Compute a correlation matrix for variables price, mpg, and weight. pwcorr price mpg weight *Create a two-way table of frequencies for rep78 and foreign with Pearson's χ2 test and Fisher's exact test. tabulate rep78 foreign, chi2 exact **# Classical tests of hypotheses *Test that the observed proportion of 0.45 in a sample size of 75 is equal to the hypothesized proportion 0.50. prtesti 75 .45 .5 *Test that the mean mpg is 20 miles per gallon, assuming that the population standard deviation is 6. ztest mpg==20, sd(6) *Test that the mean price is equal between the two groups defined by foreign. ttest price, by(foreign) *Fit a one-way ANOVA model of price for factor rep78. anova price rep78 **# Linear regression *Regress dependent variable price on continuous independent variables mpg and weight, categorical independent variable foreign, and the interaction between weight and foreign. regress price mpg weight i.foreign c.weight#foreign *Get predictions and residuals after fitting any model. predict y_hat predict epsilon_hat, residual *Interpret and visualize model results with marginal means. margins foreign, at(weight=(2000(500)4500)) plot **# Power analysis *Estimate the required sample size for a one-sample t test to achieve 80% power. power onemean 1 0 **# Simulating distributions *Generate a normally-distributed variable with mean 10 and standard deviation 2, and a binomially distributed variable with 20 trials and a 40% success probability. clear set obs 100 generate normal = rnormal(10,2) generate binomial = rbinomial(20,.4)