From 8c9d038818d01c024ab5eb0a0f51e7df8bb67434 Mon Sep 17 00:00:00 2001 From: droodman Date: Tue, 2 Apr 2024 22:19:05 -0400 Subject: [PATCH 1/3] Add drop_singletons option to partial_out() --- .gitignore | 4 ++++ src/partial_out.jl | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a2f5fc4..de0d8cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ benchmark/.sublime2Terminal.jl .vscode/settings.json +Manifest.toml +debug/debug.jl +debug/pseudoreg.csv +debug/repl.do diff --git a/src/partial_out.jl b/src/partial_out.jl index 30f866c..c4b7202 100644 --- a/src/partial_out.jl +++ b/src/partial_out.jl @@ -10,6 +10,7 @@ Partial out variables in a Dataframe * `double_precision::Bool`: Should the demeaning operation use Float64 rather than Float32? Default to true. * `tol::Real`: Tolerance * `align::Bool`: Should the returned DataFrame align with the original DataFrame in case of missing values? Default to true. +* `drop_singletons::Bool=false`: Should singletons be dropped? ### Returns * `::DataFrame`: a dataframe with as many columns as there are dependent variables and as many rows as the original dataframe. @@ -40,7 +41,8 @@ function partial_out( @nospecialize(method::Symbol = :cpu), @nospecialize(double_precision::Bool = true), @nospecialize(tol::Real = double_precision ? 1e-8 : 1e-6), - @nospecialize(align = true)) + @nospecialize(align = true), + @nospecialize(drop_singletons = false)) if (ConstantTerm(0) ∉ eachterm(f.rhs)) & (ConstantTerm(1) ∉ eachterm(f.rhs)) f = FormulaTerm(f.lhs, tuple(ConstantTerm(1), eachterm(f.rhs)...)) @@ -67,6 +69,7 @@ function partial_out( fes, ids, ids_fes = parse_fixedeffect(df, formula_fes) has_fes = !isempty(fes) + drop_singletons && drop_singletons!(esample, fes, Threads.nthreads()) nobs = sum(esample) (nobs > 0) || throw("sample is empty") From 563c32d36dffb4038dd3bb7ed628938a0ed4905b Mon Sep 17 00:00:00 2001 From: droodman Date: Tue, 2 Apr 2024 22:20:21 -0400 Subject: [PATCH 2/3] Update .gitignore --- .gitignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.gitignore b/.gitignore index de0d8cf..a2f5fc4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ benchmark/.sublime2Terminal.jl .vscode/settings.json -Manifest.toml -debug/debug.jl -debug/pseudoreg.csv -debug/repl.do From 2f9dd38d446546ba368ade57a0e4afec36cf6e54 Mon Sep 17 00:00:00 2001 From: droodman Date: Wed, 3 Apr 2024 17:03:36 -0400 Subject: [PATCH 3/3] Add dof_fes return value to partial_out() --- src/partial_out.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/partial_out.jl b/src/partial_out.jl index c4b7202..9e94bfc 100644 --- a/src/partial_out.jl +++ b/src/partial_out.jl @@ -138,6 +138,8 @@ function partial_out( residuals .= residuals .+ m end + dof_fes = mapreduce(nunique, +, fes, init=0) + # Return a dataframe out = DataFrame() j = 0 @@ -151,5 +153,5 @@ function partial_out( out[!, Symbol(y)] = residuals[:, j] end end - return out, esample, iterations, convergeds + return out, esample, iterations, convergeds, dof_fes end