Announcement

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

  • How can I put a vector variable into my regression?

    My OLS model is

    Pit = a + b1*stationit + b2*distanceit + b3*compnumit + r*Xi + s*Yi +eit

    Here Xi, I want to put variables which can show characteristics of station i. (such as station brand dummy, operation system dummy..)
    And for Yi, Region dummythat shows the region where the stationi locates.

    I guess mkmat helps to make these vector variables but don't know the exact way to use.
    mkmat brand1 brand2 brand3 operation1 operation2, matrix(X)
    and then,
    reg price station distance compnum X Y
    doesn't work. How can I put vectors into my OLS?

  • #2
    Hello Sue, command -reg- can only recognize variables but not matrix. You can either calculate the OLS results in variables format or in matrix but cannot mix them together.
    In your case, you can use global to define X first and then cite them using $X in your regress.
    global X "brand1 brand2 brand3 operation1 operation2"
    reg price station distance compnum $X Y
    Last edited by Liu Qiang; 26 May 2019, 22:32.
    2B or not 2B, that's a question!

    Comment


    • #3
      Liu Qiang gives good advice. But it is better to use a local macro than a global for this.
      Code:
      local X brand1 brand2 brand3 operation1 operation2
      reg price station distance compnum `X' Y
      Global macros are an inherently unsafe programming practice. If there is another program running that uses a global macro with the same name that you are using, you will clobber it, or it will clobber you. The bugs that results from this kind of behavior are the most difficult to find and fix. It doesn't happen often, but if it ever happens to you, I promise you, you will never want to use a global macro again in your life.

      Local macros do not have this problem as they exist only within a limited scope that does not include other programs. If another program uses the same name, it is separate from yours and they do not interfere. So global macros should be used only when there is no other way to share information between programs. (Usually this can be accomplished by passing arguments or options.) A list of variables for use in a regression command only needs to be defined within this single program. Stick with local macros and be safe.

      Comment


      • #4
        Clyde Schechter Dear professor, I didn't realize there is such a problem before you've pointed it out as I am still using global in my research now to fix the covariates. I would be wary of this. Many thanks to your kindly reminders.
        2B or not 2B, that's a question!

        Comment


        • #5
          Thank you so much.
          Thanks to your advice, I made X including characteristics of every station i.
          And now I am trying to make Y to include regional information.
          So I made 17 regional dummies and try to make Y.
          But now

          reg price station distance compnum `X' Y

          This doesn't work and it says "variable Y not found." while

          reg price station distance compnum `X'

          only works. I wonder what I have done wrong.
          Last edited by Sue Lee; 26 May 2019, 23:59.

          Comment


          • #6
            Originally posted by Sue Lee View Post
            Thank you so much.
            Thanks to your advice, I made X including characteristics of every station i.
            And now I am trying to make Y to include regional information.
            So I made 17 regional dummies and try to make Y.
            But now

            reg price station distance compnum `X' Y

            This doesn't work and it says "variable Y not found." while

            reg price station distance compnum `X'

            only works. I wonder what I have done wrong.
            Hi Sue, you also need to define Y using
            Code:
            local Y "varlist"
            2B or not 2B, that's a question!

            Comment

            Working...
            X