FixedEffectModels.jl
FixedEffectModels.jl copied to clipboard
Different residual degrees of freedom from reghdfe when using clustered VCE
If I run the example below and compare the residual degrees of freedom with that obtained from reghdfe
using the same dataset, I get 1348 from FixedEffectModels.jl
but 45 from reghdfe
.
using DataFrames, RDatasets, FixedEffectModels
df = dataset("plm", "Cigar")
reg(df, @formula(Sales ~ NDI + fe(State) + fe(Year)), Vcov.cluster(:State), weights = :Pop)
I don't know exactly how that df_r
in Stata
/reghdfe
is obtained. But, it seems that it is the number of clusters minus one. In FixedEffectModels.jl
, we are calculating nobs - size(X,2) - nunique(fe(:Year)) - 1
.
For reghdfe
, I am using version 5.6.8.
Edit:
Here are some more details on how I get the results in Stata with reghdfe
.
I first obtain the dataset from a Stata module called rdatasets
(ssc install rdatasets
).
Then, do the following:
rdatasets get plm Cigar
reghdfe sales ndi [weight=pop], a(state year) cluster(state)
Then, I compare e(df_r)
obtained above with dof_residual
obtained in the Julia example.
This may be an error, yes. What exactly are you comparing between Stata and Julia (i.e. which field of the output, or which number in the table)? Are the standard errors the same?
Hi, I was comparing e(df_r)
returned by reghdfe
with dof_residual
returned by reg
in this package.
The standard errors are different. (I think it is because of the different dofs used.)
Standard errors should be the same. This sounds like something I tried to correct in the past https://github.com/FixedEffects/FixedEffectModels.jl/issues/78
If you had some time to correct it (and add a test or two), that would be very appreciated
@matthieugomez I suspect this is something just about which dof_residual
is entered into the final result.
I will look into that later and make a pull request if I figure out whether something is messed up.