** ** Stata Code for Exercise #2 in Chapter 3 and Exercise #4 in Chapter 4 ** Ch3_SimulateBeta_StataCode.do ** /* Overview of simulation code - the "simulate" line runs the code 50 times (as determined in the "reps(50)" command) - Stata will save the beta coefficients and standard errors for each simulation. - the values of coefficient on Education for each simulation are listed in a variable called "_b_Ed" - the values of the constant for each simulation are listed in a variable called "_b_cons". - the values of the standard error for the coefficient on education for each simulation are listed in a variable called "_se_Ed" - the values of the standard error for the constant for each simulation are listed in a variable called "_se_cons". */ ** Directions for parts (a) and (b): Highlight the lines between here and "END part (a) and run in Stata clear all set seed 711 program OLS_Sim clear set obs 100 /* Set sample size */ gen Ed = 16*runiform() /* Generate education (ind. variable) */ scalar SD = 10000 /* Set value of standard deviation of error term */ gen Salary = 12000 + 1000* Ed + SD*rnormal() /* Generate salary (dep. variable) */ regress Salary Ed /* Run regression */ end simulate _b _se, reps(500): OLS_Sim /* Run simulation 50 times */ ** Display and summarize the estimated coefficients list _b_* _se* /* Coefficient estimates & std. errors for each simulation */ summarize _b* /* Summarize coefficient estimates for each simulation */ ** END part (a) ** Directions for part (c): Change the "set obs" line of the code. ** Directions for part (d): Change the "set obs" line of the code. ** Directions for part (e): Change the "StdDev" line of the code. ** Directions for part (f): Change "StdDev" line of the code. ** Directions for part (g) ** Change the "simulate _b _se, reps(50)" line of the code so that it reps(500) ** Use the following code to plot the density of the beta estimates: kdensity _b_Ed /* Density plot of beta estimates */ ** ** Exercise #4 in Chapter 4 ** ** Directions for part (d): Change the 1000 in "gen Salary = 12000 + 1000*Ed + StdDev*rnormal()" line of code to 0.