Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Factor variables in non-linear (nl) regression models

    Hi Statalisters,
    I have never used the nl regression command but tried to learn as much as I could by reading the related Stata documents and other resources available on the internet. However, I am stuck right now as I am wondering how the nl command handles interaction terms between continuous variables and factor variables.

    I ran the following regression:

    . nl (y_LN = {a}*f1*x1_LN + {b}*f2*x1_LN + {c}*f3*x1_LN + {d}*f4*x1_LN + {g}*x2_LN + {h}*x3_LN + {i}* x1_LN + {c})

    where,
    f1-f4 are four binary variables (0 , 1) that I have created to indicate the four categories of the categorical variable f;
    x1_LN is a continuous variable (it’s the log of x1) that I need to be interacted with the four categories of the variable f (f1-f4) and also as a stand-alone variable in the model;
    x2_LN and x3_LN are other continuous variables (logs of x2 and x3).

    When I used the factor notation for variable f (i.f) in the model , I got an error message; that was the reason I created the four categories f1-f4. However, after running the code above, I realized that the results table included all of the four categories f1-f4 and it did not drop one of the categories (the reference category).


    My question is: how should I revise my above code to let Stata know that f1-f4 are categories of a factor variable (f) so it would drop one of the categories as the reference category (like it would, if I run the same regression with a regular regress command: regress y_LN f1*x1_LN f2*x1_LN f3*x1_LN f4*x1_LN x2_LN x3_LN x1_LN)?

    Thank you for your help!

  • #2
    I’m only newly using menl, which handles factor variables in a very specific way. I assume the syntax for nl is similar, but I have no experience here. The way to do it in menl is by defining a linear combination. However, you could simply omit the one indicator variable corresponding to the level you want to use as a base outcome.

    Comment


    • #3
      The way how you deal with this is the second part of Leonardo's proposal "simply omit the one indicator variable corresponding to the level you want to use as a base outcome."

      In nonlinear regression (-nl- and -nlsur-) you manually control what goes into the regression and what gets estimated. Therefore only include what you want to be estimated.

      Comment


      • #4
        Thank you so much for the responses and your help.

        Comment

        Working...
        X