Closed leeper closed 6 years ago
Stata considers the AMEs for the first kind of model (where some interaction levels are missing from the data) to be not estimable:
. sysuse auto, clear
(1978 Automobile Data)
. tab rep78 foreign
Repair |
Record | Car type
1978 | Domestic Foreign | Total
-----------+----------------------+----------
1 | 2 0 | 2
2 | 8 0 | 8
3 | 27 3 | 30
4 | 9 9 | 18
5 | 2 9 | 11
-----------+----------------------+----------
Total | 48 21 | 69
. quietly regress price i.rep78##i.foreign
. margins, dydx(*)
Average marginal effects Number of obs = 69
Model VCE : OLS
Expression : Linear prediction, predict()
dy/dx w.r.t. : 2.rep78 3.rep78 4.rep78 5.rep78 1.foreign
------------------------------------------------------------------------------
| Delta-method
| dy/dx Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
rep78 |
2 | . (not estimable)
3 | . (not estimable)
4 | . (not estimable)
5 | . (not estimable)
|
foreign |
Foreign | . (not estimable)
------------------------------------------------------------------------------
Note: dy/dx for factor levels is the discrete change from the base level.
That seems wrong to me but resolving the disparity will either require conforming to Stata or going down a different path.
Oops, this is a duplicate of #71.
margins()
chokes on interactions between factors where some levels of the interaction are missing and therefore not estimated:The same issue arises in the face of perfect multicollinearity:
The issue is in variance estimation.
marginal_effects()
works fine:Clearly the issue is therefore in
jacobian()
as it attempts to take a partial derivative with respect to a coefficient that isNA
. The solution will be to remove coefficients that are missing:before doing anything. That can happen in
find_terms_in_model()
but unfortunatelyterms()
is pre-estimation not post, so it doesn't tell us what to drop: