Announcement

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

  • How to deal with the Intercept/Constant vector, when programming a command?

    Good afternoon,

    When programming an estimation command in Stata, what is the best practice of dealing with the Intercept/Constant vector of 1s?

    i) When I use a temporary variable for the vector of 1s, to not change the user's data, then I get in my resulting estimation tables some nasty looking name for the intercept such as __0000A. Added problem here is that when my command finishes executing, the temporary Intercept variable disappears (as it should), and cannot be used in subsequent postestimation commands.

    ii) When I create a variable for the vector of 1s, I fiddle with the user's data which probably I shouldn't, and in principle I could hit a name conflict with an existing variable.

    What I do currently is that I create a vector of 1s with an unlikely name
    - gen _ones=1-
    which vector I leave behind after my estimation command is done to potentially use in postestimation commands.

    iii) Stata provides a system scalar _cons, which scalar is 1. What is the use of that, how am I supposed to use it in estimation commands? I think what would have been useful here for the _cons to be a vector of 1s, and not a scalar, but maybe I just have not figured out the intended use of the system scalar _cons..

    In short, what is the best practice when we are explicitly creating an Intercept/Constant vector in our estimation commands?






  • #2
    This is such a common thing you would want to do, that programs like ml, optimize (Mata), or gmm take care of it for you. Those programs add constants by default, you only need to set an option if you don't want a constant.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment

    Working...
    X