statamarginal-effects

How to store confidence intervals from stata margins estimation?


stata experts,

I have been trying to find a way to store marginal estimations, including the p value and confidence interval.

Below is the code I have. All that I can get is the estimated marginal effect of variable I. Looks like I can't specify "ci" like what we can do for usual regression models. Is there a way to also store and present the other numbers from marginal estimations?

probit Y1 X
margin, dydx(X) post
est store m1

probit Y2 X
margins, dydx(X) post
est store m2
esttab m1 m2
esttab m1 m2, ci

Another related question is: how do I save marginal estimations for interaction terms? Example code below

probit Y2 year month year*month
margins year#month, asbalanced post

Thank you in advance!


Solution

  • Here's a way to grab p-values and confidence intervals after a margins command.

    sysuse auto, clear
    probit foreign price trunk 
    margin, dydx(price) post 
    eststo m1 
    

    The results from the margin command:

    
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
           price |   .0000268   .0000159     1.69   0.092    -4.36e-06     .000058
    ------------------------------------------------------------------------------
    

    Then the p-value and confidence interval are recoverable from the stored matrices e(b) and e(V). To get the p-value, we need the z-score which is the point estimate over the standard error (e(b)[1,1]/sqrt(e(V)[1,1]). The rest is calculating the area in the two tails using normal.

    The confidence interval is the point estimate e(b)[1,1] plus the standard error sqrt(e(V)[1,1]) times the critical value of z invnormal(0.975).

    Shown with the output so that you can see the numbers line up:

    . di "P-value: " normal(-abs(e(b)[1,1]/sqrt(e(V)[1,1])))*2
    P-value: .09186065
    
    . di "Upper bound: " e(b)[1,1] + sqrt(e(V)[1,1])*invnormal(0.975)
    Upper bound: .00005796
    
    . di "Lower bound: " e(b)[1,1] - sqrt(e(V)[1,1])*invnormal(0.975)
    Lower bound: -4.361e-06
    

    To put the p-value in a table, for example, you could use estadd:

    estadd scalar pvalue = normal(-abs(e(b)[1,1]/sqrt(e(V)[1,1])))*2
    

    And then esttab:

    esttab m1, stats(pvalue, label("P-value"))
    
    
    . esttab m1, stats(pvalue, label("P-value"))
    
    ----------------------------
                          (1)   
                                
    ----------------------------
    price           0.0000268   
                       (1.69)   
    ----------------------------
    P-value            0.0919   
    ----------------------------
    t statistics in parentheses
    * p<0.05, ** p<0.01, *** p<0.001