I’m working through the Econometrics With R online book, specifically the example in 10.3 on fixed effects regression, but I’m trying to follow along with Econometrics.jl.
Here’s the full code to reproduce the example:
using DataFramesMeta
using Econometrics
using RCall
df = rcopy(R"
library('AER')
data('Fatalities')
")
df = @chain @rget(Fatalities) begin
@transform(fatal_rate = :fatal ./ :pop .* 10_000)
end
model = fit(
EconometricModel,
@formula(fatal_rate ~ beertax + absorb(state)),
df
)
# Outputs:
Continuous Response Model
Number of observations: 336
Null Loglikelihood: -287.50
Loglikelihood: 105.99
R-squared: 0.9050
Wald: 12.19 ∼ F(1, 287) ⟹ Pr > F = 0.0006
Formula: fatal_rate ~ 1 + beertax + absorb(state)
Variance Covariance Estimator: OIM
──────────────────────────────────────────────────────────────────────────
PE SE t-value Pr > |t| 2.50% 97.50%
──────────────────────────────────────────────────────────────────────────
(Intercept) 2.37707 0.0969699 24.5135 <1e-71 2.18621 2.56794
beertax -0.655874 0.18785 -3.49148 0.0006 -1.02561 -0.286135
──────────────────────────────────────────────────────────────────────────
The book shows the output from R’s plm
package and there are some differences:
#> Estimate Std. Error t value Pr(>|t|)
#> beertax -0.65587 0.28880 -2.271 0.02388 *
Note that:
- There is no intercept
- The beertax coefficient is the same but the standard error and subsequent t and p values are different
Can anyone explain the difference? FixedEffectModels.jl produces an output that is much closer to the plm
output:
using FixedEffectModels
reg(df, @formula(fatal_rate ~ beertax + fe(state)), Vcov.cluster(:state))
Fixed Effect Model
=======================================================================
Number of obs: 336 Degrees of freedom: 2
R2: 0.905 R2 Adjusted: 0.905
F-Stat: 5.05015 p-value: 0.029
R2 within: 0.041 Iterations: 1
=======================================================================
fatal_rate | Estimate Std.Error t value Pr(>|t|) Lower 95% Upper 95%
-----------------------------------------------------------------------
beertax | -0.655874 0.291856 -2.24725 0.025 -1.22998 -0.0817668
=======================================================================