lrberge / fixest

Fixed-effects estimations
https://lrberge.github.io/fixest/
361 stars 59 forks source link

2SLS regression fit stats #445

Closed waynelapierre closed 5 months ago

waynelapierre commented 9 months ago

Is there a plan to provide p-value for cd (The Cragg-Donald test) and kpr (The Kleibergen-Paap test)? Also, the Sargan test results do not show, could you please check this issue?

lrberge commented 5 months ago

Please provide replicable examples.

Hi KPR is broken and I don't know how to fix.

Here's CD:

base = setNames(iris = c("y", "x1", "x_endo_1", "x_inst_1", "fe"))
set.seed(2)
base$x_inst_2 = 0.2 * base$y + 0.2 * base$x_endo_1 + rnorm(150, sd = 0.5)
base$x_endo_2 = 0.2 * base$y - 0.2 * base$x_inst_1 + rnorm(150, sd = 0.5)

est_iv = feols(y ~ x1 | x_endo_1 + x_endo_2 ~ x_inst_1 + x_inst_2, base)

fitstat(est_iv, "cd.p")

For Sargan:

Note that the Sargan statistic appears only when relevant (i.e. when # instr. > # endo. vars., not the case here).

est_iv = feols(y ~ x1 | x_endo_1 ~ x_inst_1 + x_inst_2, base)
fitstat(est_iv, "sargan")
#> Sargan: stat = 6.4626, p = 0.011017, on 1 DoF.