Skip to content

Commit 6a7d1cb

Browse files
committed
move around code
1 parent 4887c70 commit 6a7d1cb

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/fit.jl

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,15 @@ function reg(
140140
esample = Colon()
141141
end
142142

143-
# Compute weights
144-
if has_weights
145-
weights = Weights(convert(Vector{Float64}, view(df, esample, weights)))
146-
all(isfinite, weights) || throw("Weights are not finite")
147-
else
148-
weights = uweights(nobs)
149-
end
150143

151-
# Compute feM, an AbstractFixedEffectSolver
152144
has_intercept = hasintercept(formula)
153145
has_fe_intercept = false
154146
if has_fes
155147
if any(fe.interaction isa UnitWeights for fe in fes)
156148
has_fe_intercept = true
157149
end
158-
fes = FixedEffect[fe[esample] for fe in fes]
159-
feM = AbstractFixedEffectSolver{double_precision ? Float64 : Float32}(fes, weights, Val{method}, nthreads)
160150
end
161-
# Compute data for std errors
162-
vcov_method = Vcov.materialize(view(df, esample, :), vcov)
151+
163152
##############################################################################
164153
##
165154
## Dataframe --> Matrix
@@ -200,6 +189,28 @@ function reg(
200189
# modify formula to use in predict
201190
formula_schema = FormulaTerm(formula_schema.lhs, (tuple(eachterm(formula_schema.rhs)..., (term for term in eachterm(formula_endo_schema.rhs) if term != ConstantTerm(0))...)))
202191
end
192+
193+
# Compute weights
194+
if has_weights
195+
weights = Weights(convert(Vector{Float64}, view(df, esample, weights)))
196+
all(isfinite, weights) || throw("Weights are not finite")
197+
else
198+
weights = uweights(nobs)
199+
end
200+
201+
# Compute feM, an AbstractFixedEffectSolver
202+
has_intercept = hasintercept(formula)
203+
has_fe_intercept = false
204+
if has_fes
205+
if any(fe.interaction isa UnitWeights for fe in fes)
206+
has_fe_intercept = true
207+
end
208+
fes = FixedEffect[fe[esample] for fe in fes]
209+
feM = AbstractFixedEffectSolver{double_precision ? Float64 : Float32}(fes, weights, Val{method}, nthreads)
210+
end
211+
# Compute data for std errors
212+
vcov_method = Vcov.materialize(view(df, esample, :), vcov)
213+
203214
# compute tss now before potentially demeaning y
204215
tss_total = tss(y, has_intercept | has_fe_intercept, weights)
205216
# create unitilaized

0 commit comments

Comments
 (0)