Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: How to improve accuracy in numerical integrations using Stata

From   "Tiago V. Pereira" <>
Subject   st: How to improve accuracy in numerical integrations using Stata
Date   Fri, 23 Dec 2011 10:40:54 -0200 (BRST)

Dear statalisters,

I am using -integ- to numerically integrate a set of functions.

An example of a function to integrate:

function_y  = -2*normal((-`x'-`r'*z)/sqrt(1-`r'^2))*normalden(z)

for variable z.

In my case, the domain ranges from 0 to `x'.

So, what I am doing is  the following:

*/ ------------ start example --------------
local r = 0.1
local x = 6
drop _all
range z 0 `x' 1000
generate y  = -2*normal((-`x'-`r'*z)/sqrt(1-`r'^2))*normalden(z)
dydx     y z, gen(yprime)
integ    y z, gen(Sy)
*/ ------- end example ------------------

dis r(integral)

to gain more precision, I have manually edited -integ- to compute values
using the double format (i.e. instead of 'gen float variable = ', it is
using 'gen double variable =').

It seems that some precision is gained:

[using the exactly same code above, but using the 'double' version, one

dis r(integral)


I know that the correct answer would be something like:


which is obtained from numerical integration using a C program (supposed
to be the most precise approach I am aware of).

Do you have any ideas on how to further increase the precision for
numerical integration in Stata? The problem is that I am working on heavy
tails (alpha levels below 10^-8).

All the best,


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index