Regression Postestimation Commands in Stata: margins, pt. 2

Поділитися
Вставка
  • Опубліковано 10 гру 2024

КОМЕНТАРІ •

  • @aniagromada
    @aniagromada 5 років тому +1

    I am so grateful for the time you are spending on explaining stata. Your videos are more useful than any formal education I've received on this subject matter. Keep on good work!

  • @ecekural9572
    @ecekural9572 6 років тому

    Just seen this video, much better than any official Stata video. Please keep going!

  • @anidemolimacnauj
    @anidemolimacnauj 9 років тому +1

    Your videos are great, you explain in a very efficient way, at least from my perspective. I am fluent in Stata and keep learning things from your videos! Keep up!

    • @smilex3
      @smilex3  9 років тому

      +anidemolimacnauj Thank you! I am glad you have found these videos helpful.

  • @ricciuccio
    @ricciuccio 9 років тому

    Alan your videos are great. I'd dare to say, better than the official stata tutorials.

    • @smilex3
      @smilex3  9 років тому +1

      Thank you! They are clearly different. I like the official Stat videos because they are short but cover a lot of ground. However, I don't like their menu driven approach since this is not how most of us actually program. But, it is a great way to learn about how commands and options work together.

    • @smilex3
      @smilex3  9 років тому

      As a reminder, the official Stata videos can be found at ua-cam.com/users/statacorp

  • @vahidravaghi7103
    @vahidravaghi7103 7 років тому

    One of the best Stata tutors. Great stuff. Thanks.

  • @שריתאפל
    @שריתאפל 3 роки тому

    Thank you , this video and patr 1 were super instructive and helpful ! Now I understand the powere of marginplot

  • @hanhanzhang
    @hanhanzhang 8 років тому

    I found this just when I needed to use the command. Thanks.

  • @MaryamBanoo
    @MaryamBanoo 3 роки тому

    thanks, you are a great teacher.

  • @diablodeleon
    @diablodeleon 9 років тому

    Your videos are very very helpful! Thanks a lot

  • @ekeomageorge8979
    @ekeomageorge8979 Рік тому

    This is great
    Thanks alot

  • @1001nguyen
    @1001nguyen 10 років тому

    thank you very much, this one and pt.1 are very helpful :)

  • @AdrianaCastilloC
    @AdrianaCastilloC 4 роки тому

    Hi Alan, your video is GREAT! Thank you so much. I want to ask you if you know if I can use the margins estimations and plots using the command "xtscc" with fixed effects. When I try to use it, I got the error: "factor variables may not contain noninteger values".
    Thank you in advance.

  • @joodyu
    @joodyu 9 років тому

    Thanks so much this is of great help!

  • @freshnews2970
    @freshnews2970 4 роки тому

    Thank you very much. Where I get the link to downloap your do-file. I'm very interest. Thank in advance.

    • @smilex3
      @smilex3  4 роки тому

      Hi Soro, I do not have Web space to store the do-file. But, they can easily be duplicated form the videos.

  • @cathymorgan8182
    @cathymorgan8182 9 років тому

    These are great demonstration videos, thanks. I have one quick question. i would like to fit an xtreg model on a subset of observations and then predict the outcome for all the observations. I know this is achievable with -predict but is there a way to use with margins and/or marginsplot?

    • @smilex3
      @smilex3  9 років тому

      +Cathy Morgan Yes, this is possible. the margins command operates on all cases that are non-missing on the independent variables, allowing the calculation of out of sample marginal effects. The margins post-estimation command allows the optional use of the if and in command modifiers. So you could do the following, assuming you have cases:
      margins if !e(sample)
      Or if you wanted in-sample margins only you could:
      margins if e(sample)
      Best,
      Alan

  • @202areza
    @202areza 8 років тому +1

    You are awesome!

    • @smilex3
      @smilex3  8 років тому

      I'm glad you found this video useful.

  • @nimrarasheeed5066
    @nimrarasheeed5066 6 років тому

    Sir do you have any video on marginplot in logistic regression

    • @smilex3
      @smilex3  6 років тому

      Hi Nimra, I do not have a video on margins and marginsplot after estimating logistic or logit models. But, everything works pretty much the same way as after estimating a regression model except for two differences. Actually, one difference and one complication. The difference is that the margins produce predicted probabilities. The complication is if you prefer to produce odds ratios. Regardless, you can play around with the Stata code below to show you how you can begin producing visualizations of your limited dependent variable models.
      Best,
      Alan
      /* Load some data to use */
      sysuse auto, clear
      /* Recode the rep79 variable into two outcome groups */
      capture drop rep78_2cat
      recode rep78 (1/3=1) (4/5=2), generate(rep78_2cat)
      /* Estimate a model */
      logistic foreign c.mpg##c.mpg i.rep78_2cat
      /* Margins showing predicted probabilities by various levels of mpg */
      margins, at(mpg=(10(2)40))
      marginsplot, recast(line) noci plotopts(lw(thick)) name(p1, replace)
      /* Add repair variable to the mix */
      margins rep78_2cat, at(mpg=(10(2)40))
      marginsplot, recast(line) noci plotopts(lw(thick)) name(p2, replace)
      /* Convert probabilities to odds ratios */
      margins rep78_2cat, expression(exp(predict(xb)))
      marginsplot, yline(1, lw(thick) lp(dash) lc(cranberry)) ///
      plotopts(connect(none)) xlabel(.5 " " 1 2 2.5 " ") name(p3, replace)
      margins rep78_2cat, at(mpg=(10(5)40)) expression(exp(predict(xb)))
      marginsplot, yline(1, lw(thick) lp(dash) lc(cranberry)) ///
      plotopts(connect(none)) name(p4, replace)

  • @JuciaraNunes
    @JuciaraNunes 7 років тому

    How can I deal woth an error "not sorted" in estimating margins and marginsplot?

    • @smilex3
      @smilex3  7 років тому

      Juciara, can you please replicate the problem with a Stata-supplied dataset? From the command window type "help dta_examples" followed by the "Enter" key. Maybe the auto.dta dataset ("sysuse auto, clear"). With data and analogous Stata code, I may be able to determine what is going on.

  • @JuciaraNunes
    @JuciaraNunes 7 років тому

    Do you have any video for marginsplot in xtdpd moldels?

  • @mar355
    @mar355 8 років тому

    When you create the marginsplot for educations and father education, the other variables (age and race) are held constant? At their mean?

    • @smilex3
      @smilex3  8 років тому +1

      +Marvin Aliaga Yes, the mean, but you can set the values any way you want.

    • @mar355
      @mar355 8 років тому

      +Alan Neustadtl Hi Alan, are you considering doing post estimations tutorials for logistic regression?

    • @smilex3
      @smilex3  8 років тому

      +Marvin Aliaga Yes, I would like to do that. The big difference in OLS and logistic regression margins is that the estimated values from logistic regression (and other limited dependent variable models) are by default expressed as probabilities.

    • @mar355
      @mar355 8 років тому

      Yes! And that the probabilities does not have a linear function (s shape). That is why it is more confusing for me.

    • @smilex3
      @smilex3  8 років тому

      Correct, the probabilities tend to be linear near the middle of the distribution but depart from normality at both the bottom and top ends.

  • @2dinottee6minuti
    @2dinottee6minuti 9 років тому

    wow!

    • @smilex3
      @smilex3  9 років тому

      +Valeria Resta Hopefully, a good wow. Best, Alan

    • @2dinottee6minuti
      @2dinottee6minuti 9 років тому

      +Alan Neustadtl for sure it's a good one! I am struggling to build a discrete choice model for 2011 elections in Tunisia, and your tutorials eased the pain ;)

  • @lucaventura1150
    @lucaventura1150 6 років тому

    how can I combine two marginsplots in the same graph?

    • @smilex3
      @smilex3  6 років тому

      luca, this is difficult to answer because unless your independent variables are standardized, it is difficult to plot thing s with very different metrics. But, it may be possible to 1) use standardized measures, and 2) use the undocumented "saving" option to margins. You can get more help by typing "help undocumented" in the command window (yes, there is documentation to some undocumented commands and options). Basically, you can 1) created standardized measures, 2) regress your DV on the IV's, 3) generate margins foreach variables and save them to a file, 5) merge the two sets of margins, and 6) plot them. Here is a quick example that might give you some clues about your particular situation:
      sysuse auto, clear
      egen zweight=std(weight)
      egen zlength=std(length)
      regress mpg zweight zlength
      margins, at(zweight=(-3(.25)3)) saving(margins1, replace)
      marginsplot, recast(line) noci name(g1, replace)
      margins, at(zlength=(-3(.25)3)) saving(margins2, replace)
      marginsplot, recast(line) noci name(g2, replace)
      use _at _margin using margins1, clear
      rename _margin weight
      merge 1:1 _n using margins2
      rename _margin length
      keep _at weight length
      graph twoway (line weight _at) ///
      (line length _at)

    • @lucaventura1150
      @lucaventura1150 6 років тому

      Thank you so much, it was really helpful. I managed to combine two marginsplots, however I have a further question: how can I merge three graphs? Thank you again for your precious help

    • @smilex3
      @smilex3  6 років тому

      luca, there is a difference, I think, between "merging" and "combining" graphs. The code I showed you placed two plots in one graph. To add a third plot you would just extend the code I provided to accommodate a third variable. Here is an example of combining three graphs:
      sysuse auto, clear
      hist mpg, name(g1)
      tw(scatter mpg weight) (lfit mpg weight), name(g2)
      kdensity weight, name(g3)
      graph combine g1 g2 g3

    • @lucaventura1150
      @lucaventura1150 6 років тому

      Yes sorry, I meant merging before. However, since I am new to Stata could you please show me how to merge a possible third graph in the example above?
      Thank you so much I really appreciate your help

    • @smilex3
      @smilex3  6 років тому

      Here is an extension to a third variable in a 3-IV variable regression model:
      sysuse auto, clear
      egen zweight=std(weight)
      egen zlength=std(length)
      egen zdisplacement=std(displacement)
      regress mpg zweight zlength zdisplacement
      margins, at( zweight=(-3(.25)3)) saving(margins1, replace)
      margins, at( zlength=(-3(.25)3)) saving(margins2, replace)
      margins, at(zdisplacement=(-3(.25)3)) saving(margins3, replace)
      use _at _margin using margins1, clear
      rename _margin weight
      merge 1:1 _n using margins2
      rename _margin length
      keep _at weight length
      merge 1:1 _n using margins3
      rename _margin displacement
      keep _at weight length displacement
      tw (line weight length displacement _at)