* Sampling Distribution of a Least Squares Estimator * * Keywords: * regression, ols, sampling, distribution, monte carlo, histogram * * Description: * We illustrate how to simulate a sampling distribution of a Least Squares * Estimator by estimating 500 regressions from 100 generated datapoints * each and plotting its Histogram * * Author(s): * Noel Roy * Skif Pankov * * Source: * William H. Greene, Econometric Analysis - 7th Edition * Pearson International Edition, Chapter 4, Example 4.1 (page 94) * * Defining the variable b and setting it equal to 500 dim b 500 * Specifying the sample size - in our case, this determines how many datapoints * to generate for each variable sample 1 100 * Specifying not to print out any commands during a do-loop set nodoecho * Initiating a do-loop with 500 iterations do #=1, 500 * Generating variables w and x by drawing from a Normal distribution with * a unit variance genr w=nor(1) genr x=nor(1) * Generating remaining variables e and y genr e=0.5*w genr y=0.5+0.5*x+e * Running an OLS regression of newly generated variables y on x, speficying to * store the estimated coefficients in a vector c. "?" in front of the ols command * suppresses any output we'd normally get ?ols y x / coef = c * The vector C has two elements, the estimate of the slope and the * estimate of the constant. The former is denoted by C(1). We want * to save this in the B vector. We do this using the GEN1 command. This * command is like the GENR command, but generates a constant rather than a * series. * Saving the element 1 from vector c (estimated slope) as an #'th element of * the vector b gen1 b(#)=c(1) * Stopping the loop endo * Redefining a sample for plotting a histogram sample 1 500 * Plotting a historgram of b, specifying to split the data into 30 groups graph b / histo groups=30 stop * Comment: * Because of the random nature of estimation, the exact histogram * produced may differ from the one in the book in some details, but * the key feature (shape) will remain the same