From e10537d6e80a0e1eed1cba772dc1d9dcc04e380e Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Thu, 24 Apr 2025 14:10:08 -0400 Subject: [PATCH 1/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e3251e..94cb212 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build status](https://github.com/matthieugomez/InteractiveFixedEffectModels.jl/workflows/CI/badge.svg)](https://github.com/matthieugomez/InteractiveFixedEffectModels.jl/actions) +[![Build status](https://github.com/FixedEffects/InteractiveFixedEffectModels.jl/workflows/CI/badge.svg)](https://github.com/FixedEffects/InteractiveFixedEffectModels.jl/actions) [![Coverage Status](https://coveralls.io/repos/matthieugomez/InteractiveFixedEffectModels.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/matthieugomez/InteractiveFixedEffectModels.jl?branch=master) ## Installation From b83973ec943c0b40187487ff79801cb11221ea1a Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Thu, 24 Apr 2025 14:18:40 -0400 Subject: [PATCH 2/6] Update fit.jl --- src/fit.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fit.jl b/src/fit.jl index a504ad2..1fc76d8 100644 --- a/src/fit.jl +++ b/src/fit.jl @@ -67,8 +67,9 @@ function regife( Symbol(fesymbol(a)) ∉ factor_vars && error("FixedEffect should correspond to id or time dimension of the factor model") end end - fes, ids, fekeys, formula = FixedEffectModels.parse_fixedeffect(df, formula) - has_fes = !isempty(fes) + formula, formula_fes = FixedEffectModels.parse_fe(formula) + has_fes = formula_fes != FormulaTerm(ConstantTerm(0), ConstantTerm(0)) + fes, feids, fekeys = FixedEffectModels.parse_fixedeffect(df, formula_fes) has_fes_intercept = false ## Compute factors, an array of AbtractFixedEffects if has_fes From 0c2b6f0e8f9f4a7eddcc449ace360e1eb4fccca1 Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Thu, 24 Apr 2025 14:19:08 -0400 Subject: [PATCH 3/6] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index b48a9be..3ccff24 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "InteractiveFixedEffectModels" uuid = "80307280-efb2-5c5d-af8b-a9c15821677b" -version = "1.3.0" +version = "1.3.1" [deps] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" From 629d26d5933234d49e04ee27c56732eb5fff8a4e Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Thu, 24 Apr 2025 14:22:42 -0400 Subject: [PATCH 4/6] Update fit.jl --- src/fit.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fit.jl b/src/fit.jl index 1fc76d8..743deec 100644 --- a/src/fit.jl +++ b/src/fit.jl @@ -270,8 +270,8 @@ function regife( # get fixed effect newfes, b, c = solve_coefficients!(oldresiduals, feM; tol = tol, maxiter = maxiter) for j in 1:length(fes) - augmentdf[!, ids[j]] = Vector{Union{Float64, Missing}}(missing, length(esample)) - augmentdf[esample, ids[j]] = newfes[j] + augmentdf[!, feids[j]] = Vector{Union{Float64, Missing}}(missing, length(esample)) + augmentdf[esample, feids[j]] = newfes[j] end end end From 1b30628ca412633b4ba9e98fa5649389e092434a Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Thu, 24 Apr 2025 14:24:09 -0400 Subject: [PATCH 5/6] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3ccff24..9ede411 100644 --- a/Project.toml +++ b/Project.toml @@ -23,7 +23,7 @@ Vcov = "ec2bfdc2-55df-4fc9-b9ae-4958c2cf2486" [compat] DataFrames = "0.21, 0.22, 1" FillArrays = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 1" -FixedEffectModels = "1.11" +FixedEffectModels = "1.12" FixedEffects = "2" GroupedArrays = "0.3" LeastSquaresOptim = "0.7, 0.8" From 04a7c4fc2b291b1ceb4b38933fa9c0c8633458ad Mon Sep 17 00:00:00 2001 From: Matthieu Gomez Date: Thu, 24 Apr 2025 14:44:57 -0400 Subject: [PATCH 6/6] Update fit.jl --- src/fit.jl | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/fit.jl b/src/fit.jl index 743deec..9447984 100644 --- a/src/fit.jl +++ b/src/fit.jl @@ -69,20 +69,27 @@ function regife( end formula, formula_fes = FixedEffectModels.parse_fe(formula) has_fes = formula_fes != FormulaTerm(ConstantTerm(0), ConstantTerm(0)) + fes, feids, fekeys = FixedEffectModels.parse_fixedeffect(df, formula_fes) - has_fes_intercept = false - ## Compute factors, an array of AbtractFixedEffects + has_fe_intercept = any(fe.interaction isa UnitWeights for fe in fes) + + # remove intercept if absorbed by fixed effects + if has_fe_intercept + formula = FormulaTerm(formula.lhs, tuple(InterceptTerm{false}(), (term for term in eachterm(formula.rhs) if !isa(term, Union{ConstantTerm,InterceptTerm}))...)) + end + has_intercept = hasintercept(formula) + + if has_fes - if any([isa(fe.interaction, Ones) for fe in fes]) - formula = FormulaTerm(formula.lhs, tuple(ConstantTerm(0), (t for t in eachterm(formula.rhs) if t!= ConstantTerm(1))...)) - has_fes_intercept = true + if any(fe.interaction isa UnitWeights for fe in fes) + has_fe_intercept = true end fes = FixedEffect[fe[esample] for fe in fes] feM = AbstractFixedEffectSolver{Float64}(fes, weights, Val{:cpu}) end - has_intercept = ConstantTerm(1) ∈ eachterm(formula.rhs) + iterations = 0 @@ -102,7 +109,7 @@ function regife( formula_schema = apply_schema(formula, schema(formula, subdf, contrasts), StatisticalModel) y = convert(Vector{Float64}, response(formula_schema, subdf)) - tss_total = tss(y, has_intercept || has_fes_intercept, weights) + tss_total = tss(y, has_intercept | has_fe_intercept, weights) X = convert(Matrix{Float64}, modelmatrix(formula_schema, subdf)) @@ -228,7 +235,7 @@ function regife( # compute various r2 nobs = sum(esample) rss = sum(abs2, residualsm) - _tss = tss(ym ./ sqrtw, has_intercept || has_fes_intercept, weights) + _tss = tss(ym ./ sqrtw, has_intercept | has_fe_intercept, weights) r2_within = 1 - rss / _tss rss = sum(abs2, residuals)