Dear Statalist,
By way of background to this question, I am attempting to build a model predicting individuals' labor income throughout their working careers using the Current Population Survey. Among other estimation methods, I would like to use the Elastic Net and force the inclusion of indicator variables for age in my sample and optionally include interactions of age with other demographic characteristics (e.g. education, marital status, etc.).
However, when I attempt to do this, I run into two errors. The first is a "base conflict error" relating to my age variable (i.e. age: factor variable base category conflict). In my attempt to fix this error message, I generate an identical copy of my age variable via clonevar and include that variable as the optional interaction term. Upon doing this, I get a rather inscrutable conformability error.
The following code is a minimum working example (code plus resulting error messages) using the automobile dataset replicating the issue:
This brings me to two questions.
By way of background to this question, I am attempting to build a model predicting individuals' labor income throughout their working careers using the Current Population Survey. Among other estimation methods, I would like to use the Elastic Net and force the inclusion of indicator variables for age in my sample and optionally include interactions of age with other demographic characteristics (e.g. education, marital status, etc.).
However, when I attempt to do this, I run into two errors. The first is a "base conflict error" relating to my age variable (i.e. age: factor variable base category conflict). In my attempt to fix this error message, I generate an identical copy of my age variable via clonevar and include that variable as the optional interaction term. Upon doing this, I get a rather inscrutable conformability error.
The following code is a minimum working example (code plus resulting error messages) using the automobile dataset replicating the issue:
Code:
sysuse auto, clear
global other_indepvars "c.mpg c.headroom c.trunk c.weight c.length c.turn c.displacement c.gear_ratio i.foreign"
cap noisily elasticnet linear price (i.rep78) $other_indepvars i.rep78#($other_indepvars), rseed(8973) nolog
rep78: factor variable base category conflict
clonevar rep78_for_lasso = rep78
cap noisily elasticnet linear price (i.rep78) $other_indepvars i.rep78_for_lasso#($other_indepvars), rseed(8973) nolog
1o.rep78_for_lasso#1o.foreign omitted
2o.rep78_for_lasso#1o.foreign omitted
1o.rep78_for_lasso#1o.foreign omitted
2o.rep78_for_lasso#1o.foreign omitted
1o.rep78_for_lasso#1o.foreign omitted
2o.rep78_for_lasso#1o.foreign omitted
_LASSO_RESULT_APPEND_OBJ::compact_B(): 3200 conformability error
_LASSO_RESULT_APPEND_OBJ::compact(): - function returned error
_LASSO_RESULT_APPEND_OBJ::merge(): - function returned error
_LASYS_merge(): - function returned error
<istmt>: - function returned error
- Does anyone know of a way to force inclusion of a series of indicators in an elastic model and optionally allow for interactions between those indicators and other variables?
- If cloning the indicator variable and including it in the optional variables is the way to go, any suggestions on fixing the conformability issue?

Comment