Announcement

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

  • Emulate margins, dydx if custom command only supports predict

    dear all,
    I have gotten so used to the margins command that I have found no way to emulate it, when a custom command only offers predict as a postestimation. Is there any simple way to emulate margins, dydx when you can only usge predict?
    Thank you!
    Tim

  • #2
    Assuming you know the necessary formulas, you may be able to use the expressions option of margins. See the help.

    Also, slides 31-34 of

    https://www3.nd.edu/~rwilliam/xsoc73994/Margins01.pdf

    show how you could compute AMEs for a logistic regression if the margins command didn't exist. (But this wouldn't give you the standard errors. Further, the way I use the predict command might not work with whatever command you are working with, so you may need gen commands too that use the correct formula.)

    Again, if you know what the formulas are, you can probably do it. If you don't know the formulas you have to figure them out.

    You might also write the author of the routine to encourage them to add support for margins. In the case of my gologit program, I wrote gologit2_p.ado, which basically supercedes Stata's default predict command and adds the options that are needed to get the predicted values I want. (That may not be the best example, because it is fairly complicated.) Or, you could just look at some of Stata's own commands, like logit_p.ado. Most users may not even realize such commands exist, because they never call them directly, but Stata calls them for various post-estimation commands like predict and margins. When writing my own such commands, I typically used an existing command (e.g. mlogit_p.ado) and figured out how I needed to modify it to work correctly with my program.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 18.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      I'll add that I would personally find a lot of commands far less helpful if the predict and margins commands for them only allowed xb. For example, other than sign and significance, how many people have a clear idea of what the coefficients in a logistic regression mean? I suspect Tim has already discovered that on his own, which is why he wants to add other options to whatever user-written command he is talking about.

      If you ever write your own estimation command, you may find it very helpful if you write your own predict command as well. It will require some extra work, but you may find that your estimation command gets a lot more use (or more effective use) if you make the effort.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 18.5 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Come to think of it, it usually isn’t that hard for a user written estimation commands to add support for things like factor variable notation, svy, and multiple imputation. But many older user-written commands were written before Stata supported such things, or the authors may not have known how to add support. If there is some great 10 or 15 year old command you use all the time, you might encourage the authors to consider updating it.

        As a sidelight — I used to make suggestions to Scott Long all the time for his spost13 commands. He finally responded Hey, maybe you could make improvements in your commands instead of always asking me to change mine. So I figured out how to add factor variable support to oglm and gologit2. His 2014 book has a convoluted example for gologit2 (correct at the time) that can now be done much more easily.
        Last edited by Richard Williams; 23 Jan 2022, 07:38.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 18.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Which command you use? I mean you want to emulate margin after what?

          Comment

          Working...
          X