Search code examples
rfixest

Where are the 1st stage F statistics located in a "fixest" object?


When I run an 2SLS regression, say:

library(fixest)
twosls <- feols(Sepal.Length ~ Petal.Length | Species ~ Petal.Width, data = iris)
summary(twosls)
fitstat(twosls, ~ivf)

I can't seem to find the F-stats in twosls by looking through the object. I assume it will be somewhere inside 2sls$iv_first_stage but no luck.

The f-stat appears when i run summary() and also by using fitstat(2sls, ivf) but I am trying to extract it directly from the object.

Summary

... F-test (1st stage), Speciesversicolor: stat = 13.4, p = 3.545e-4, on 1 and 147 DoF. F-test (1st stage), Speciesvirginica : stat = 28.3, p = 3.735e-7, on 1 and 147 DoF. ...

Fitstat

F-test (1st stage), Speciesversicolor: stat = 13.4, p = 3.545e-4, on 1 and 147 DoF. F-test (1st stage), Speciesvirginica : stat = 28.3, p = 3.735e-7, on 1 and 147 DoF.


Solution

  • As mentioned in a comment, I wouldn't be suprised if it's not part of twosls before printing. I.e. you would need to calculate it manually if you do not want to use print(), summary(), or fitstat(), but I haven't checked (yet).

    If via fitstat() is ok, then try

    library(fixest)
    twosls = feols(Sepal.Length ~ Petal.Length | Species ~ Petal.Width, data = iris)
    fs = fitstat(twosls, ~ivf)
    data.frame(vn = names(fs[[1]]), list2DF(fs))
    
       vn ivf1..Speciesversicolor ivf1..Speciesvirginica
    1 stat                13.37481               28.33797
    2    p            0.0003545351           3.734527e-07
    3  df1                       1                      1
    4  df2                     147                    147
    

    You might want to add first_stage, second_stage.