You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Z =convert(Matrix{Float64}, modelmatrix(formula_iv_schema, subdf))
201
+
Z =modelmatrix(formula_iv_schema, subdf)
202
+
203
+
for c ineachcol(Z)
204
+
esample2 .&= .!ismissing.(c)
205
+
end
206
+
207
+
# PR #109, to be removed when fixed in StatsModels
208
+
ifany(esample2 .==false)
209
+
Xendo = Xendo[esample2,:]
210
+
Z = Z[esample2,:]
211
+
end
212
+
213
+
Xendo =convert(Matrix{Float64}, Xendo)
214
+
all(isfinite, Xendo) ||throw("Some observations for the endogenous variables are infinite")
215
+
216
+
Z =convert(Matrix{Float64}, Z)
198
217
all(isfinite, Z) ||throw("Some observations for the instrumental variables are infinite")
218
+
219
+
ifsize(Z, 2) <size(Xendo, 2)
220
+
throw("Model not identified. There must be at least as many ivs as endogeneneous variables")
221
+
end
199
222
200
223
# modify formula to use in predict
201
224
formula_schema =FormulaTerm(formula_schema.lhs, (tuple(eachterm(formula_schema.rhs)..., (term for term ineachterm(formula_endo_schema.rhs) if term !=ConstantTerm(0))...)))
# it doesn't take into account time and group indices!
278
+
@testset"missings from @formula"begin
279
+
m0 =@formula y ~ x1_lagged +fe(id1)
280
+
m1 =@formula y ~lag(x1) +fe(id1)
281
+
test_lags(m0, m1, "ols: _ ~ lag")
282
+
283
+
m0 =@formula y_lagged ~ x1 +fe(id1)
284
+
m1 =@formulalag(y) ~ x1 +fe(id1)
285
+
test_lags(m0, m1, "ols: lag ~ _")
286
+
287
+
m0 =@formula y ~ (x1_lagged ~ z1_lagged) +fe(id1)
288
+
m1 =@formula y ~ (lag(x1) ~lag(z1)) +fe(id1)
289
+
test_lags(m0, m1, "iv: _ ~ (lag ~ lag)")
290
+
291
+
m0 =@formula y ~ (x1_lagged ~ z1) +fe(id1)
292
+
m1 =@formula y ~ (lag(x1) ~ z1) +fe(id1)
293
+
test_lags(m0, m1, "iv: _ ~ (lag ~ _)")
294
+
295
+
m0 =@formula y ~ (x1 ~ z1_lagged) +fe(id1)
296
+
m1 =@formula y ~ (x1 ~lag(z1)) +fe(id1)
297
+
test_lags(m0, m1, "iv: _ ~ (_ ~ lag)")
298
+
299
+
# NOTE: The case where the df contains missings and the formula contains missings cannot be handled yet. The case with :x1_m1 would actually work, but the case with :x1_m2 would not. This because the missings in x1_m1 and x1_m2 are removed BEFORE the the lag is applied.
300
+
301
+
m0 =@formula y_lagged ~ x1_m1 +fe(id1)
302
+
m1 =@formulalag(y) ~ x1_m1 +fe(id1)
303
+
test_lags_broken(m0, m1, "ols: lag ~ _, with missings")
304
+
305
+
m0 =@formula y_lagged ~ x1_m2 +fe(id1)
306
+
m1 =@formulalag(y) ~ x1_m2 +fe(id1)
307
+
test_lags_broken(m0, m1, "ols: lag ~ _, with missings")
308
+
309
+
m0 =@formula y ~ (x1_m1 ~ z1_lagged) +fe(id1)
310
+
m1 =@formula y ~ (x1_m1 ~lag(z1)) +fe(id1)
311
+
test_lags_broken(m0, m1, "iv: _ ~ (_ ~ lag), with missings")
312
+
313
+
m0 =@formula y ~ (x1_m2 ~ z1_lagged) +fe(id1)
314
+
m1 =@formula y ~ (x1_m2 ~lag(z1)) +fe(id1)
315
+
test_lags_broken(m0, m1, "iv: _ ~ (_ ~ lag), with missings")
0 commit comments