Announcement

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

  • Post-estimation, predicting the dependent variable with a change to one or more independent variables

    Dear Stata community,

    I'm attempting to predict the value of a dependent variable if one of the independent variables is changed.

    For example, let's suppose I've modeled testscore as a function of independent variables height, weight, and cupsofcoffee:

    regress testscore height weight cupsofcoffee

    I can generate predictions with
    predict testscorehat

    But now I want to predict what everyone's testscore would have been if they'd drank twice as many cups of coffee. What command do I use? Predict? Adjust? Something else? And with what syntax?

    If I wanted to predict what would happen if cupsofcoffee had a single value for everyone, e.g. if everyone had one cup of coffee, i.e. I could run:
    adjust cupsofcoffee=1
    (https://www.stata.com/support/faqs/s...ct-and-adjust/)

    But if I try to double everyone's coffee intake by running
    generate doublecoffee=cupsofcoffee*2
    adjust cupsofcoffee, by(doublecoffee)

    I get the error message 'too many values', which seems to mean that the the vector doublecoffee has too many individual values.

    It seems that I might be able to make an out-of-sample prediction on a "new" dataset that is the same as the old data set but for the doubled coffee. (https://www.stata.com/manuals13/u20.pdf)
    But this seems like a lot of work for what I would think would be a simple command.

    I'm sure this must be a routine command or syntax, but I'm having a difficult time finding it.

    Thanks,

    Jonah

  • #2
    Welcome to Statalist.

    It seems to me that what you ask for can be accomplished without much effort by
    Code:
    generate savecoffee = cupsofcoffee
    replace cupsofcoffee = 2*cupsofcoffee
    predict ...
    replace cupsofcoffee = savecoffee

    Comment


    • #3
      Hi William,

      Thanks for your quick response. That works perfectly. Exactly what I was looking for.

      Best,

      Jonah

      Comment

      Working...
      X