Using gret l for Principles of Econometrics, 4th Edition
Script for t-values and p-values
One thing we've shown in this chapter is that many of the results obtained using the pull-down menus (often referred to as the GUI) in gretl can be obtained using hansl from the console or in a script. In fact, the gretl’s GUI is merely a front-end to its programming language.[12] In this chapter we used the pvalue and critical functions to get p-values or critical values of statistics. The following script accumulates what we’ve covered and completes the examples in the text.
1 open "@gretldirdatapoefood. gdt"
2 ols food_exp const income
3
3 #One sided test (Ha: b2 > zero)
4 scalar tratio1 = ($coeff(income) - 0)/ $stderr(income)
5 scalar c1 = critical(t,$df,.05)
6 scalar p1 = pvalue(t,$df, tratio1)
7 printf "The statistic = %.4f, 5%% critical value = %.4f and
8 pvalue = %.4fn",tratio1, c1,p1
10
її #One sided test (Ha: b2>5.5)
12 scalar tratio2 = ($coeff(income) - 5.5)/ $stderr(income)
13 scalar c2 = critical(t,$df,.05)
14 scalar p2 = pvalue(t,$df, tratio2)
їв printf "The statistic = %.4f, 5%% critical value = %.4f and
16 pvalue = %.4fn",tratio2, c2,p2
17
17 #One sided test (Ha: b2<15)
18 scalar tratio3 = ($coeff(income) - 15)/ $stderr(income)
19 scalar c3 = -1*critical(t,$df,.05)
20 scalar p3 = pvalue(t,$df, abs(tratio3))
21 printf "The statistic = %.4f, 5%% critical value = %.4f and
22 pvalue = °/0.4fn",tratio3, c3,p3
24
23 #Two sided test (Ha: b2 not equal 7.5)
24 scalar tratio4 = ($coeff(income) - 7.5)/ $stderr(income)
25 scalar c4 = critical(t,$df,.025)
26 scalar p4 = 2*pvalue(t,$df, abs(tratio4))
27 printf "The statistic = %.4f, 5%% critical value = %.4f and
28 pvalue = %.4fn",tratio4, c4,p4
31
29 #Confidence interval
30 scalar lb = $coeff(income) - critical(t,$df,0.025) * $stderr(income)
31 scalar ub = $coeff(income) + critical(t,$df,0.025) * $stderr(income)
32 printf "The 95%% confidence interval is (%.4f, %.4f)n",lb, ub
36
33 #Two sided test (Ha: b2 not equal zero)
34 scalar tratio5 = ($coeff(income) - 0)/ $stderr(income)
35 scalar c5 = critical(t,$df,.025)
36 scalar p5 = 2*pvalue(t,$df, abs(tratio5))
37 printf "The statistic = %.4f, 5%% critical value = %.4f and
38 pvalue = %.4fn",tratio5, c5,p5
The pvalue function in gretl measures the area of the probability distribution that lies to the right of the computed statistic. If the computed t-ratio is positive and your alternative is twosided, multiply the result by 2 to measure the area to the left of its negative; this can be seen in lines 28 and 40. The other function used here is printf. This function is a fancy way of printing your results to the screen and its use is explained in detail in section 5.2.2. Because the lines are long, the continuation command () discussed in chapter 1 was also used. This tells gretl that the current line continues to the next.
If the t-ratio is negative, gretl won’t compute the area (and you wouldn’t want it to, anyway). This is what happened for tratio3 in the script and I used the absolute value function, abs( ), in line 21 to get its positive value. The area to the right of the positive value is equivalent to the area left of the negative value. Hence, the computation is correct.
Basically, proper use of the pvalue in one-sided tests of a single hypothesis requires a little thought. Too much thought, in my opinion. I would avoid it unless you are comfortable with its use. In other hypothesis testing contexts (e. g., x2 and F-tests) p-values are much easier to use correctly. I use them freely in those cases. With t-tests or z-tests (normal distribution), it is just easier conduct a test by comparing the computed value of your statistic to the correct critical value.
The output from the script is nice and neat, thanks to the use of printf and the use of set echo off. This appears in Figure 3.9 below. The set echo off command used at the beginning of the chapter ending scripts reduces what is printed to the screen when the script is executed. Ordinarily, gretl will write (echo) each command executed back to the screen before it produces the requested output. This is useful in most cases, but when running a longer script, it is bothersome. The set echo off turns the default echoing of commands off. To turn it back on, use set echo on.
Model 1: OL5, using observations 1-40 Dependent variable: food_exp
coefficient std. error t-ratio p-value
const 33.4160 43.4102 1.922 0.0622 *
income 10.2096 2.09326 4.877 1.9Se-05 ***
Mean dependent var 283.5735 5.D. dependent var 112.6752 Sum squared resid 304505.2 S. E. of regression 39.51700 R-squared 0.385002 Adjusted R-squared 0.368818 F(l, 38} 23.78884 P-value(F) 0.000019 Log-likelihood -235.5088 Akaike criterion 475.0176 Schwarz criterion 478.3954 Hannan-Quinn 476.2389
The statistic = 4.8774, 5% critical value = 1.6860 and pvalue = 0.0000 The statistic = 2.2499, 5% critical value = 1.6860 and pvalue = 0.0152 The statistic = -2.2885, 5% critical value = -1.6360 and pvalue = 0.0139 The statistic = 1.2945, 5% critical value = 2.0244 and pvalue = 0.2033 The 95% confidence interval is (5.9721, 14.4472)
The statistic = 4.8774, 5% critical value = 2.0244 and pvalue = 0.0000
Figure 3.9: The results produced by the script to test hypotheses in the simple regression.