Announcement

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

  • how to generate a new equation by using regression coefficient

    Hi, I am wondering if I can generate a new equation y = a + b1 * gender + b2 * age where the "a", "b1", "b2" is from the regression coefficient of data1.
    Then, I need to use new observations from data2 to put into the new equation to get new y.

    I already run the regression results of data1 and store the coefficient into matrix by the following command:
    local b1 = m[1,2]
    local b2 = m[1,3]
    However, I do not know how to generate a new equation by using regression coefficient of data1.
    Because I still need to put observations from data2 into this equation, would I need to save the equation into a new dofile?
    Does anyone have idea to slove this issue?
    Thank you!
    Last edited by WEN-CHIA HUANG; 25 Feb 2023, 01:01.

  • #2
    Originally posted by WEN-CHIA HUANG View Post
    . . .the "a", "b1", "b2" is from the regression coefficient of data1.
    Then, I need to use new observations from data2 to put into the new equation to get new y.
    To get new y from the regression coefficients for data1, use predict. Something like the following.
    Code:
    use data1
    generate byte data1 = 1
    
    append using data2
    replace data1 = 0 if missing(data1)
    
    regress y i.gender c.age if data1
    predict double new_y, xb // <= here
    
    list data1 gender age y new_y, noobs sepby(data1)

    Comment


    • #3
      Originally posted by Joseph Coveney View Post
      To get new y from the regression coefficients for data1, use predict. Something like the following.
      Code:
      use data1
      generate byte data1 = 1
      
      append using data2
      replace data1 = 0 if missing(data1)
      
      regress y i.gender c.age if data1
      predict double new_y, xb // <= here
      
      list data1 gender age y new_y, noobs sepby(data1)
      Thank you very much! It helps me a lot.

      Comment


      • #4
        You're welcome.

        One thing that you might not have noticed because I was emphasizing the predict line of code, but the dataset-indicating variable is used primarily to restrict the regression model to the data1 dataset. I neglected to emphasize that above, and so I'll point it out here (see below),
        Code:
        regress y i.gender c.age if data1

        Comment


        • #5
          Originally posted by Joseph Coveney View Post
          You're welcome.

          One thing that you might not have noticed because I was emphasizing the predict line of code, but the dataset-indicating variable is used primarily to restrict the regression model to the data1 dataset. I neglected to emphasize that above, and so I'll point it out here (see below),
          Code:
          regress y i.gender c.age if data1
          Thanks! I've revised my code and successfully run the regression.
          I did notice " if data1 " in your code, and I also did it in mine.
          Thanks for the reminder.

          Comment

          Working...
          X