Announcement

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

  • coefplot and predicted values

    Dear all,

    I want to plot the predicted outcomes of several experimental groups from a linear regression analysis. #

    I use -margins- with -at()- to specify the values of interest.
    However -coefplot- (SJ, Ben Jann) plots the coefficients of the regression preceding margins and does not plot the value predicted by margins.
    -margins- followed by -marginsplots- does plot the desired coefficients but obviously only for one -margins- result at a time.

    I have found it that -matrix list r(table)- contains the information I want to plot. But I did not figure out how to tell -coefplot- to use this matrix (and the matrices of the other preceding -margin- commands)

    To clarify what I hope for, here is a reproducible example. In my case the explanatory variable are three dichotomous variables for the experimental conditions.
    Code:
    sysuse auto, clear
    ssc install coefplot
    
    eststo clear
    regress mpg foreign turn
    eststo: margins, at(foreign=0 turn=40)
    eststo: margins, at(foreign=1 turn=40)
    eststo: margins, at(foreign=0 turn=41)
    eststo: margins, at(foreign=1 turn=41)
    marginsplot //Plots the desired estimated (of the last calculation)
    coefplot est1 est2 est3 est4
    matrix list r(table)
    I am grateful for any advice.

  • #2
    I am not a user of coefplot, so I'm not entire surely what your desired result looks like. But I think I get what you want. Have you tried:
    Code:
    sysuse auto, clear
    
    regress mpg foreign turn
    
    margins, at(foreign = (0 1) turn = (40 41))
    marginsplot

    Comment


    • #3
      Yes, thank you Clyde, this would be the more elegant coding. And it allows to use marginsplot because -margins- is only executed once.
      However, in my actual case this leads to undesired combinations. This is why I want to run margins several times.

      I am puzzled. What I am trying to do seems to be a very easy application, I thought.

      Comment


      • #4
        Well, the other thing is that -margins- (and -marginsplot-, too) have a saving() option so that you can create data sets containing the points. Then you can put all those data sets together and use -graph twoway- to construct your plot.

        Also, if the problem is that you are over-generating combinations of variable levels that are not of interest, you can just use multiple -at()- options in the same -margins- command to get precisely what you want. For example:

        Code:
        sysuse auto, clear
        
        regress mpg rep78 turn
        
        margins, at(rep78 = (1 2) turn = (40 41)) at(rep78 = (3 4) turn = (50 51))
        marginsplot
        This involves four values each of rep78 and turn, but produces only the selected 8 pairings of interest. You can get any set of combinations you want this way.
        Last edited by Clyde Schechter; 31 Oct 2016, 19:06.

        Comment


        • #5
          I was unaware of margins, saving().
          Thank you!
          Since I had to calculate predicted values of different regression models, I saved the various results of margins, appended the datasets and plotted them with -eclplot- (ssc, Newton)

          Thanks!

          Comment

          Working...
          X