Search code examples
stata

Return the CI lower and upper limits from nl in Stata


After running the nl command in stata, how can I get the lower and upper limit of the 95% Confidence Interval.

to get the point estimate, you just do:

global point_est = _b[/beta]

and the standard error can be saved like this:

global std_err = _se[/beta]

so how to get the upper and lower CI bounds? its not normal, so:

95%CI-upper != point_est + 1.96 * std_err

Thanks for any help!


Solution

  • You are mistaken: nl, as every generic estimation command, produces symmetric confidence intervals. (Some bootstrap confidence intervals are asymmetric, and some commands that naturally allow for exp, log or logit scale, like logistic or proportion, can produce CIs on these scales, and then back-transform them into asymmetric ones.) It just takes the estimated coefficients and standard errors, and produces the confidence intervals using exactly the formula you sort of cited. See help estcom.

    . sysuse auto, clear
    . nl (price = exp( {a} + {b}*mpg ) )
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
              /a |   9.882335   .2007597    49.22   0.000     9.482128    10.28254
              /b |  -.0569546   .0105899    -5.38   0.000    -.0780651    -.035844
    ------------------------------------------------------------------------------
    
    . di reldif( _b[/a] - invt(e(df_r),0.975)*_se[/a], 9.482128 )
    2.582e-09
    
    . di reldif( _b[/a] + invt(e(df_r),0.975)*_se[/a], 10.28254 )
    1.944e-07
    

    Also, do not use global macros unless you absolutely have to. This is what programmers call a "smell". Their only intended purpose is to pass stuff between programs that cannot be passed by any other meaningful way. The system of syntax with parsing, plus the system of of return values, takes care of most of the needs. Instead, globals are probably placeholders of some kind.