# ftest

### Author: Maarten L. Buis

ftest compares two nested models estimated using regress and performs an F-test for the null hypothesis that the constraint implicit in the restricted model holds. For example if a variable is left out of the restricted model, the implicit constraint is that the coefficient for that variable equals zero. ftest is a convenience command; anything that can be done with ftest can be done with test, and it will produce exactly the same results. The difference is that with test the constraint needs to be explicitly specified, while with ftest the constraint is implicit. ftest can be convenient when all the models you want to compare are already estimated and stored for use by for example Ben Jann's estout.

This package can be installed by typing into Stata: ssc install ftest

.

### Examples

These are the different ways in which you can refer to the different models that you want to compare.

```
. sysuse auto, clear
(1978 Automobile Data)

. reg price mpg foreign

Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  2,    71) =   14.07
Model |   180261702     2  90130850.8           Prob > F      =  0.0000
Residual |   454803695    71  6405685.84           R-squared     =  0.2838
Total |   635065396    73  8699525.97           Root MSE      =  2530.9

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -294.1955   55.69172    -5.28   0.000    -405.2417   -183.1494
foreign |   1767.292    700.158     2.52   0.014     371.2169    3163.368
_cons |   11905.42   1158.634    10.28   0.000     9595.164    14215.67
------------------------------------------------------------------------------

. est store a

. reg price mpg

Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  1,    72) =   20.26
Model |   139449474     1   139449474           Prob > F      =  0.0000
Residual |   495615923    72  6883554.48           R-squared     =  0.2196
Total |   635065396    73  8699525.97           Root MSE      =  2623.7

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -238.8943   53.07669    -4.50   0.000    -344.7008   -133.0879
_cons |   11253.06   1170.813     9.61   0.000     8919.088    13587.03
------------------------------------------------------------------------------

. est store b

. ftest a b
Assumption: b nested in a

F(  1,      71) =      6.37
prob > F =    0.0138

. ftest a .
Assumption: . nested in a

F(  1,      71) =      6.37
prob > F =    0.0138

. ftest a
Assumption: . nested in a

F(  1,      71) =      6.37
prob > F =    0.0138

.
[do-file]```

ftest is just a convenience command; these results could also be obtained by using the official Stata command test

```
. sysuse auto, clear
(1978 Automobile Data)

. reg price mpg foreign

Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  2,    71) =   14.07
Model |   180261702     2  90130850.8           Prob > F      =  0.0000
Residual |   454803695    71  6405685.84           R-squared     =  0.2838
Total |   635065396    73  8699525.97           Root MSE      =  2530.9

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -294.1955   55.69172    -5.28   0.000    -405.2417   -183.1494
foreign |   1767.292    700.158     2.52   0.014     371.2169    3163.368
_cons |   11905.42   1158.634    10.28   0.000     9595.164    14215.67
------------------------------------------------------------------------------

. test foreign

( 1)  foreign = 0

F(  1,    71) =    6.37
Prob > F =    0.0138

.
[do-file]```

It is necessary that both models are estimated on the same sample. This requirement can easily be violated if some variables have missing values, like rep78 in the example below

```
. sysuse auto, clear
(1978 Automobile Data)

. reg price mpg rep78

Source |       SS       df       MS              Number of obs =      69
-------------+------------------------------           F(  2,    66) =   11.06
Model |   144754063     2  72377031.7           Prob > F      =  0.0001
Residual |   432042896    66  6546104.48           R-squared     =  0.2510
Total |   576796959    68  8482308.22           Root MSE      =  2558.5

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -271.6425   57.77115    -4.70   0.000    -386.9864   -156.2987
rep78 |   666.9568   342.3559     1.95   0.056     -16.5789    1350.492
_cons |   9657.754    1346.54     7.17   0.000       6969.3    12346.21
------------------------------------------------------------------------------

. est store a

. reg price mpg

Source |       SS       df       MS              Number of obs =      74
-------------+------------------------------           F(  1,    72) =   20.26
Model |   139449474     1   139449474           Prob > F      =  0.0000
Residual |   495615923    72  6883554.48           R-squared     =  0.2196
Total |   635065396    73  8699525.97           Root MSE      =  2623.7

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -238.8943   53.07669    -4.50   0.000    -344.7008   -133.0879
_cons |   11253.06   1170.813     9.61   0.000     8919.088    13587.03
------------------------------------------------------------------------------

. est store b

. ftest a b
models are estimated on different samples
r(198);

.
[do-file]```

This can be fixed by making sure that all models are estimated on the same sample using the if qualifier while estimating the models, like in the examples below.

```
. sysuse auto, clear
(1978 Automobile Data)

. reg price mpg rep78

Source |       SS       df       MS              Number of obs =      69
-------------+------------------------------           F(  2,    66) =   11.06
Model |   144754063     2  72377031.7           Prob > F      =  0.0001
Residual |   432042896    66  6546104.48           R-squared     =  0.2510
Total |   576796959    68  8482308.22           Root MSE      =  2558.5

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -271.6425   57.77115    -4.70   0.000    -386.9864   -156.2987
rep78 |   666.9568   342.3559     1.95   0.056     -16.5789    1350.492
_cons |   9657.754    1346.54     7.17   0.000       6969.3    12346.21
------------------------------------------------------------------------------

. est store a

. reg price mpg if e(sample)

Source |       SS       df       MS              Number of obs =      69
-------------+------------------------------           F(  1,    67) =   17.58
Model |   119910002     1   119910002           Prob > F      =  0.0001
Residual |   456886957    67  6819208.31           R-squared     =  0.2079
Total |   576796959    68  8482308.22           Root MSE      =  2611.4

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -226.3607   53.98091    -4.19   0.000     -334.107   -118.6143
_cons |   10965.23   1191.468     9.20   0.000      8587.05    13343.41
------------------------------------------------------------------------------

. est store b

. reg price mpg if rep78 < .

Source |       SS       df       MS              Number of obs =      69
-------------+------------------------------           F(  1,    67) =   17.58
Model |   119910002     1   119910002           Prob > F      =  0.0001
Residual |   456886957    67  6819208.31           R-squared     =  0.2079
Total |   576796959    68  8482308.22           Root MSE      =  2611.4

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |  -226.3607   53.98091    -4.19   0.000     -334.107   -118.6143
_cons |   10965.23   1191.468     9.20   0.000      8587.05    13343.41
------------------------------------------------------------------------------

. est store c

. ftest a b
Assumption: b nested in a

F(  1,      66) =      3.80
prob > F =    0.0557

. ftest a c
Assumption: c nested in a

F(  1,      66) =      3.80
prob > F =    0.0557

[do-file]```