Announcement

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

  • How to obtain the estimated dependent variable by replacing the regressors on Stata?

    Hello! I'm fairly new to Stata and to Econometrics and I'm wondering if it's possible to obtain the estimated dependent variable of a regression on Stata.

    With this I mean, after obtaining the coefficients of the regressors, replace the variables with given numbers and alongside the coefficients get the dependent variable.

    Say you have this regression: y = b0 + b1 x1 + b2 x2 and using a database with the variables you compute "reg y x1 x2 " and get the coefficients (e.g. b0 = 1 , b1 = 2 , b2 = 3). Now say you are given the values x1 = 10 and x2 = 20 and you want to get the "y". I know this is trivial but can you compute the y on Stata having all that information? (I mean if there's a command for that)

    I'm sorry if this is an easy question but I'm just having Econometrics this semester and I'm totally new to Stata.

    Thank you in advance

  • #2
    I think that you're looking for lincom, which would be used in this manner:
    Code:
    regress y c.(x1 x2)
    lincom _b[_cons] + 10 * _b[x1] + 20 * _b[x2]
    You could also use margins instead of lincom (and it would be less typing).
    Code:
    margins , at(x1 = 10 x2 = 20)
    If you're looking for predictions, that is, y at observed x1-x2 pairs, then you'd use predict
    Code:
    predict double y_hat, xb
    and it would leave the predictions in the dataset.
    Code:
    help lincom
    help margins
    help predict

    Comment


    • #3
      Sorry for the very late reply. This worked wonders. Thank you!

      Comment

      Working...
      X