Announcement

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

  • Predict conditional mean

    I would like to predict the mean and standard error conditional on some dummies in a data set containing four variables: y, year, control1 and control2. That is, I would like to estimate E[y | year] for the following linear model y = \alpha + \beta * year + \gamma * control1 + \delta * control2 + \varepsilon. I run the following Stata code:

    Code:
    xi: reg y i.year control1 control2
    collapse y control1 control2, by(year)
    predict cond_mean, xb
    predict cond_mean, stdp
    Is this correct? Or am I really doing something entirely/subtly different?

  • #2
    You don't say what version of Stata you are using, but the xi: syntax has been superseded by factor variable notation in more recent Stata versions (see help fvvarlist). Following the regression command, you should use the margin command to get your estimates.
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Originally posted by Fredrik Paues View Post
      I would like to predict the mean and standard error conditional on some dummies in a data set containing four variables: y, year, control1 and control2. That is, I would like to estimate E[y | year] for the following linear model y = \alpha + \beta * year + \gamma * control1 + \delta * control2 + \varepsilon. I run the following Stata code:

      Code:
      xi: reg y i.year control1 control2
      collapse y control1 control2, by(year)
      predict cond_mean, xb
      predict cond_mean, stdp
      Is this correct? Or am I really doing something entirely/subtly different?
      Note Carole's caution about the -xi- prefix.

      Then, -predict- will predict the actual value of -xb- for each person in the data, and no more. I think what you want is probably margins, e.g.

      Code:
      reg y i.year control1 control2
      margins, over(year)
      margins, at(year = (0 1))
      The first -margins- command will present average predicted mean Ys over each value of year. So, for each value of year, -margins- will calculate predicted y, keeping all covariates as is.

      The second -margins- command is subtly different. It will show predicted y over all observations, changing their values of year to 0 and 1 respectively. So, it's as if you changed all observations to have year 0 and year 1. You should read up on the Stata manual for margins, or Richard Williams' presentation on margins linked below. (Richard Williams is a frequent poster and he frequently posts here.)

      https://www3.nd.edu/~rwilliam/stats/Margins01.pdf
      Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

      When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

      Comment

      Working...
      X