Announcement

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

  • Marginal effects vs. Predicted value

    Dear colleagues,

    I noted that graphs from margins and predict shows somewhat different patterns. I was interested in the marginal effects of income#time. I did this in two ways:

    1. margins , at(T=(0(1)9) Sincome=(0 4)) // income 0= lowest 4=highest

    2. predict PS
    graph twoway lfit PS T if Sincome ==4 || lfit PS T if Sincome ==0, legend(lab(1 "highest_inc") lab(2 "lowest_inc")) // qfit is also applied

    Is it just a matter of intercept?

    Thanks!




    Attached Files

  • #2
    Well, you certainly can't expect -qfit- results to look like -marginsplot- output from a linear model.

    As for the distinction between the -lfit- plots and your -marginsplot- graph, because you do not show the original regression model, I cannot be sure what I'm about to say is correct. But I'm pretty confident that the difference arises due to other variables in the model. What you get from your -lfit-s are regression lines that involve only your outcome variable and T, at two levels of income. But -margins- also adjusts everything for any other variables in the regression command that you used before -margins-. To illustrate this, study and then run the following code:

    Code:
    clear*
    sysuse auto
    
    regress price i.foreign##c.mpg
    predict prediction
    
    graph twoway (lfit prediction mpg if foreign == 0) ///
        (lfit prediction mpg if foreign == 1), name(from_predict)
        
    margins foreign, at(mpg = (10(10)40))
    marginsplot, name(from_margins)
    
    graph combine from_predict from_margins, ycommon altshrink name(two_vars) ///
        title(Two Variables) nocopies
    
    regress price i.foreign##c.mpg length
    predict prediction_with_length
    
    graph twoway (lfit prediction_with_length mpg if foreign == 0) ///
        (lfit prediction_with_length mpg if foreign == 1), name(from_predict, replace)
        
    margins foreign, at(mpg = (10(10)40))
    marginsplot, name(from_margins, replace)
    
    graph combine from_predict from_margins, ycommon altshrink name(three_vars) ///
        title(Three Variables) nocopies
    graph combine two_vars three_vars, altshrink rows(2) nocopies
    You will note that when there are no additional variables in the regression model, the -lfit-s and the -marginsplot- produce the same results. But when an additional variable is added, the -lfits- are the same as they were without that additional variable, whereas the -marginsplot- results change in response to the added variable.

    Comment


    • #3
      Wow, this is surprising. At a graduate school, I had learned that "lift" can be used with a predicted value controlling for others, especially for an interaction model. I controlled a bunch of variables in the model, of course. Thanks for your advice.

      Comment


      • #4
        Originally posted by Clyde Schechter View Post
        Well, you certainly can't expect -qfit- results to look like -marginsplot- output from a linear model.

        As for the distinction between the -lfit- plots and your -marginsplot- graph, because you do not show the original regression model, I cannot be sure what I'm about to say is correct. But I'm pretty confident that the difference arises due to other variables in the model. What you get from your -lfit-s are regression lines that involve only your outcome variable and T, at two levels of income. But -margins- also adjusts everything for any other variables in the regression command that you used before -margins-. To illustrate this, study and then run the following code:

        Code:
        clear*
        sysuse auto
        
        regress price i.foreign##c.mpg
        predict prediction
        
        graph twoway (lfit prediction mpg if foreign == 0) ///
        (lfit prediction mpg if foreign == 1), name(from_predict)
        
        margins foreign, at(mpg = (10(10)40))
        marginsplot, name(from_margins)
        
        graph combine from_predict from_margins, ycommon altshrink name(two_vars) ///
        title(Two Variables) nocopies
        
        regress price i.foreign##c.mpg length
        predict prediction_with_length
        
        graph twoway (lfit prediction_with_length mpg if foreign == 0) ///
        (lfit prediction_with_length mpg if foreign == 1), name(from_predict, replace)
        
        margins foreign, at(mpg = (10(10)40))
        marginsplot, name(from_margins, replace)
        
        graph combine from_predict from_margins, ycommon altshrink name(three_vars) ///
        title(Three Variables) nocopies
        graph combine two_vars three_vars, altshrink rows(2) nocopies
        You will note that when there are no additional variables in the regression model, the -lfit-s and the -marginsplot- produce the same results. But when an additional variable is added, the -lfits- are the same as they were without that additional variable, whereas the -marginsplot- results change in response to the added variable.
        Hi Clyde Schechter, thank you so much for this example! I know it's an old post, but this is the exact problem I'm having - maginsplot and lfit (based on predict) are giving me different results. Looking at each individual observation, prediction and predict_with_length are having different predicted values. But why when you plot them, they are the same? Why is margins accounting for added variables but predict does not? Thank you so much in advance!

        Comment


        • #5
          Looking at each individual observation, prediction and predict_with_length are having different predicted values. But why when you plot them, they are the same?
          They are not the same when you plot them. In fact, the code you are quoting from the earlier post never does plot them together. What the code does is plot linear regression lines fitted to them. And although the two predict* variables are different, their best fit linear relationships to mpg are the same.

          Why is margins accounting for added variables but predict does not?
          -margins- is designed to do that; predict is not. I don't really understand the question. Perhaps if you look at the methods for each command in their respective chapters in the PDF documentation that comes installed with your Stata you will see it in more detail.

          Comment

          Working...
          X