# set verbose off /* gretl script to illustrate the perils of not including an intercept when running an OLS regression */ # create an "empty" dataset with space for 20 observations nulldata 20 # create an artificial independent variable x = index # 1, 2, 3, ... # artificial standard normal error term u = normal() # the true parameter values: in "real life" these are unknown # but in simulation we get to set them! b0 = 10 # y-intercept b1 = 1 # slope # manufacture artificial dependent variable y = b0 + b1*x + u # run simple regression including a constant ols y const x SSR = $ess # retrieve sum of squared residuals TSS = sst(y) # find total sum of squares for y # calculate R-squared manually R2 = 1 - (SSR/TSS) print R2 # compute and print the sum of residuals uhat_sum = sum($uhat) print uhat_sum # now run OLS _without_ a constant ols y x SSR = $ess TSS = sst(y) # calculate R-squared in the standard way R2 = 1 - (SSR/TSS) print R2 uhat_sum = sum($uhat) print uhat_sum