Skip to content

Commit bed6bea

Browse files
committed
convert
1 parent 6a7d1cb commit bed6bea

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/fit.jl

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,11 @@ function reg(
160160
formula_schema = apply_schema(formula, s, FixedEffectModel, has_fe_intercept)
161161

162162
# Obtain y
163-
# for a Vector{Float64}, convert(Vector{Float64}, y) aliases y
164-
y = convert(Vector{Float64}, response(formula_schema, subdf))
165-
all(isfinite, y) || throw("Some observations for the dependent variable are infinite")
163+
_y_ = response(formula_schema, subdf)
166164

167165
# Obtain X
168-
Xexo = convert(Matrix{Float64}, modelmatrix(formula_schema, subdf))
169-
all(isfinite, Xexo) || throw("Some observations for the exogeneous variables are infinite")
166+
_Xexo_ = modelmatrix(formula_schema, subdf)
167+
170168

171169
response_name, coef_names = coefnames(formula_schema)
172170
if !(coef_names isa Vector)
@@ -176,20 +174,33 @@ function reg(
176174
if has_iv
177175
subdf = Tables.columntable((; (x => disallowmissing(view(df[!, x], esample)) for x in endo_vars)...))
178176
formula_endo_schema = apply_schema(formula_endo, schema(formula_endo, subdf, contrasts), StatisticalModel)
179-
Xendo = convert(Matrix{Float64}, modelmatrix(formula_endo_schema, subdf))
180-
all(isfinite, Xendo) || throw("Some observations for the endogenous variables are infinite")
177+
_Xendo_ = modelmatrix(formula_endo_schema, subdf)
178+
181179
_, coefendo_names = coefnames(formula_endo_schema)
182180
append!(coef_names, coefendo_names)
183181

184182
subdf = Tables.columntable((; (x => disallowmissing(view(df[!, x], esample)) for x in iv_vars)...))
185183
formula_iv_schema = apply_schema(formula_iv, schema(formula_iv, subdf, contrasts), StatisticalModel)
186-
Z = convert(Matrix{Float64}, modelmatrix(formula_iv_schema, subdf))
184+
_Z_ = modelmatrix(formula_iv_schema, subdf)
185+
186+
# for a Vector{Float64}, convert(Vector{Float64}, y) aliases y
187+
Xendo = convert(Matrix{Float64}, _Xendo_)
188+
all(isfinite, Xendo) || throw("Some observations for the endogenous variables are infinite")
189+
190+
Z = convert(Matrix{Float64}, _Z_)
187191
all(isfinite, Z) || throw("Some observations for the instrumental variables are infinite")
188192

189193
# modify formula to use in predict
190194
formula_schema = FormulaTerm(formula_schema.lhs, (tuple(eachterm(formula_schema.rhs)..., (term for term in eachterm(formula_endo_schema.rhs) if term != ConstantTerm(0))...)))
191195
end
192196

197+
# for a Vector{Float64}, convert(Vector{Float64}, y) aliases y
198+
y = convert(Vector{Float64}, _y_)
199+
all(isfinite, y) || throw("Some observations for the dependent variable are infinite")
200+
201+
Xexo = convert(Matrix{Float64}, _Xexo_)
202+
all(isfinite, Xexo) || throw("Some observations for the exogeneous variables are infinite")
203+
193204
# Compute weights
194205
if has_weights
195206
weights = Weights(convert(Vector{Float64}, view(df, esample, weights)))

0 commit comments

Comments
 (0)