Announcement

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

  • Tricking Stata to do margins after a custom-written program

    I'm trying to estimate two models that are basically a probit and tobit, but not quite. To estimate the model, I have to program a custom likelihood function. However, the average marginal effects I am interested in are exactly the ones from a probit and tobit. To get these marginal effects, I know I can program them myself to get the point estimate and the delta method standard error. However, I was wondering if there was a way to trick Stata into thinking my custom program was a probit or tobit. The outline of the code I have in mind is as follows

    Code:
    program define my_prog, eclass
           syntax /*....*/
           
           ml model /*....*/
           
           ereturn post B V
           ereturn local cmd "probit"
           ereturn /*....*/
    end
          
          
    my_prog /*..*/
    margins, dydx(/*...*/)
    I'm able to get margins to run. However, for probit, it doesn't give the average marginal effect of y, only the marginal effect of the latent variable, which is just the beta coefficient. And for tobit, it crashes. Are there any suggestions on what I should put in for ereturn to make this work? I've been doing esample, but I wasn't sure what other things needed to be a part of the ereturn. Thank you.



  • #2
    What is needed is a (small) second program that makes the predictions you like. That program will typically be called my_prog_p. In my_prog.ado you add the line ereturn local predict "my_prog_p". That way predict and margins knows that that is the program that handles the predictions for my_prog. You can read more about that at help _pred_se
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment

    Working...
    X