# st: RE: RE: Fitting the integral of a unknown function

 From "Feiveson, Alan H. (JSC-SK311)" To "statalist@hsphsun2.harvard.edu" Subject st: RE: RE: Fitting the integral of a unknown function Date Fri, 6 Feb 2009 08:09:25 -0600

```For even more accuracy, you can try Gaussian integration. See my presentation on how to implement it in Stata at the 2004 North American Users Group Meeting.

http://ideas.repec.org/s/boc/asug04.html

Al Feiveson

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Steichen, Thomas J.
Sent: Thursday, February 05, 2009 4:01 PM
To: 'statalist@hsphsun2.harvard.edu'
Subject: st: RE: Fitting the integral of a unknown function

You can approximate it by summing over i = 2 to k:  (x[i]-x[i-1]) * (y[i] + y[i-1]) / 2 Where [] indicates a subscript and k is the number of (x,y) pairs.

This is the trapezoid approach where
(x[i]-x[i-1]) is the width of each interval.
(y[i-1] + y[i]) / 2 is the "half-height" of that interval.
The product is the area under that section of the curve.
The sum is the total area.

In simple Stata code:

sort x
gen areaparts = (x[_n]-x[_n-1]) * (y[_n] + y[_n-1]) / 2 egen area = total(areaparts)

-----------------------------------
Thomas J. Steichen
steicht@rjrt.com
-----------------------------------

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tiago V. Pereira
Sent: Thursday, February 05, 2009 4:00 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: Fitting the integral of a unknown function

Dear statalisters,

I am unsure if the topic is 100% related to the objective I am looking for, because I failed to find an exact expression in English.

I have two positively correlated variables (say, X and Y) that can range from 0 to 1.

For every value of X (0 to 1) I have values for Y, giving a non-linear curve. Is it possible to calculate the area under the curve having only these data?

All the best,

Tiago

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

CONFIDENTIALITY  NOTE:  This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney-client or other legal privileges, and/or proprietary non-public information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and/or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```