Bookmark and Share

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


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

Re: st: Re: Features for Stata 14


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Re: Features for Stata 14
Date   Thu, 5 Sep 2013 09:48:32 +0200

On Thu, Sep 5, 2013 at 8:40 AM, Liu,Zhong  wrote:
> A dataset has two variables, say ‘v1’ and ‘v2’. Either of them has ‘N’
> number of observations. I want to generate a third variable, say ‘v3’. The
> 1st element of ‘v3’ is the numerical integration with the 1st element of
> ‘v1’ as the lower limit to the integral and the 1st element of ‘v2’ as the
> upper limit to the integral. Similarly, the 2nd element of ‘v3’ is the
> numerical integration with the 2nd element of ‘v1’ as the lower limit to the
> integral and the 2nd element of ‘v2’ as the upper limit. And so on. The
> function integrand is known STATA function such as 'normal(x)' or defined by
> a program written by users.

For many distributions there is no need to do this numerically. In
your example, I suppose you mean -normalden(x)- for the function that
is to be integrated instead of -normal(x)-. -normalden()- gives you
the PDF of the normal distribution (the well known bell shaped curve),
while -normal()- gives you the CDF (an S-shaped curve). In that case
the solution is straightforward, as you can see in the example below.
In -help density_functions- you can find a list of distributions for
which this solution has been implemented.

*------------------ begin example ------------------
// create some example data
clear
input v1 v2
-2 2
-1 1
end

// compute your integrals
gen v3 = normal(v2) - normal(v1)

// admire the result
list
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

Ps. As you can read in the Statalist FAQ
(http://www.stata.com/support/faqs/resources/statalist-faq/#spell) it
is Stata not STATA.

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------

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


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