Using gret l for Principles of Econometrics, 4th Edition
Confidence Intervals
Confidence intervals are obtained using the scalar command in the same way as in chapter 3. A 95% confidence interval for в2, the coefficient of the price variable is generated:
1 ols sales const price advert —vcv
2 scalar bL = $coeff(price) - critical(t,$df,0.025) * $stderr(price)
3 scalar bU = $coeff(price) + critical(t,$df,0.025) * $stderr(price)
4 printf "nThe lower = %.2f and upper = %.2f confidence limitsn", bL, bU
The output from the script is:
The lower = -10.09 and upper = -5.72 confidence limits
This nifty piece of output uses the function called, printf. printf stands for print format and it is used to gain additional control over how results are printed to the screen. In this instance we’ve combined descriptive text and numerical results. The syntax is a bit tricky, so I will explain a little about it. I will be using it extensively in the rest of this book so that you get the used to it. Once you use it, its mystery quickly evaporates-the syntax is really quite elegant.
The printf function is divided into two parts. The first part consists of what you want to write to the screen, and the second contains the numbers from your output that you want placed within the first part.
------------------ Dressing up printed output with printf ------------
printf "nThe lower = %.2f and upper = %.2f confidence limitsn", bL, bU
The first part, called the format string, is enclosed in double quotes. The n command stands for ‘new line’ and it basically tells gretl to issue a line feed (in old computer lingo, that means go to a new line). It is used at the beginning and the end of the format string and is not strictly necessary. In this case, a line feed is given before and after the format string to give a little more white space to your printed output. If you want line feeds, be sure to put these inside the double quotes that enclose the format string.
Within this ‘sentence’ or ‘format string’ are two format commands. A format command tells gretl how the numerical results are to be printed. A format command begins with the / symbol and is followed by instructions about how many digits of the numerical result you want it to print. These formats are basically adopted from the C programming language. %f a fixed point format and the number that falls between the /. and f indicates how many decimal places to print. So, %.2f tells gretl to print only two numbers to the right of the decimal.
Recognized numeric formats are %s, %e, %E, %f, %g, %G and /d1, in each case with the various modifiers available in C. Examples: the format %.10g prints a value to 10 significant figures; %12.6f prints a value to 6 decimal places, with a width of 12 characters. The format %s should be used for strings.
The second part of the printf command contains the values to be printed at the each of the format commands. There has to be one result for each format command. These are separated by commas. Since there are two format commands, gretl is expecting two results to be listed. The result computed and stored in bL will be printed at the first format command, %.2f, and the one in bU will be printed at the second %.2f. The values to be printed must follow the format string, separated by commas. These values should take the form of either (a) the names of variables, (b) expressions that are valid for the genr command, or (c) the special functions varname() or date().
Remember, you can also summon the 95% confidence intervals from the model window using the pull-down menu by choosing Analysis>Confidence intervals for coefficients. The confidence interval for ft2 is shown below in Figure 5.4.
You can also estimate intervals for linear combinations of parameters as we did in chapter 4. Suppose Big Andy wants to increase sales next week by lowering price and spending more on advertising. If he increases advertising by $800 and lowers price by 40 cents the change in expected sales would be
A = E (sales!) — E(sales0) = -0.4,02 + 0.8в3 (5.4)
The estimate of A is obtained by replacing the unknown parameters with the least squares estimates. The standard error of this linear combination can be calculated in the same fashion as discussed in section 3.6. A 90% interval is constructed using the script:
Figure 5.4: The confidence intervals produced from the GUI through the model window. In the model window, choose Analysis>Confidence intervals for coefficients |
1 scalar chg = -0.4*$coeff(price)+0.8*$coeff(advert)
2 scalar se_chg=sqrt((-0.4)"2*$vcv[2,2]+(0.8"2)*$vcv[3,3]+2*(-0.4)*(0.8)*$vcv[2,3])
3 scalar lb = chg-critical(t,$df,.05)*se_chg
4 scalar ub = chg+critical(t,$df,.05)*se_chg
5 printf "nExpected Change = %.4f and SE = %.4fn",chg, se_chg
6 printf "nThe 90%% confidence interval is [%.3f, %.3f]n",lb, ub
This produces the expected result:
Expected Change = 4.6532 and SE = 0.7096 The 90% confidence interval is [3.471, 5.836]