FixedEffects / FixedEffectModels.jl

Fast Estimation of Linear Models with IV and High Dimensional Categorical Variables
Other
225 stars 46 forks source link

Get " run `reg` with the option save = :residuals" despite doing exactly that #224

Closed droodman closed 1 year ago

droodman commented 1 year ago

I'm running Julia 1.8.5 in Windows. I do

using DataFrames, FixedEffectModels, StatsModels
df = DataFrame(rand(collect(0:5), 20, 2), :auto)
est = reg(df, @formula(x1 ~ fe(x2)); save=:residuals)
residuals(est, df)

and I get

ERROR: "To access residuals in a fixed effect regression,  run `reg` with the option save = :residuals, and then access residuals with `residuals()`"
Stacktrace:
 [1] residuals(m::FixedEffectModel, t::DataFrame)
   @ FixedEffectModels C:\Users\drood\.julia\packages\FixedEffectModels\xGOsh\src\FixedEffectModel.jl:101
 [2] top-level scope
   @ d:\OneDrive\Documents\Work\Econometrics\Wild cluster\Young\test.jl:29

It seems like I'm doing exactly what the message is telling me to do. Am I doing something wrong or is this a bug?

matthieugomez commented 1 year ago

Thanks for the report. You should run residuals(est) instead of residuals(est, df).

Just created a PR to correct the wording: https://github.com/FixedEffects/FixedEffectModels.jl/pull/225

droodman commented 1 year ago

Thank you. Can you also check the Readme file? It seems jumbled. Do you use save=:residuals or save=true? And is it none or :none?

The option save can be set to one of the following: none (default) to save nothing :residuals to save residuals, :fe to save fixed effects. You can access the result with residuals() and fe()...

and

with the option save = true, a dataframe aligned with the initial dataframe with residuals and, if the model contains high dimensional fixed effects, fixed effects estimates (use residuals or fe on the output of reg)

matthieugomez commented 1 year ago

Sure, thanks for the comment