Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Generating a sequence of numbers in Mata


From   "Ben Jann" <[email protected]>
To   [email protected]
Subject   Re: st: Generating a sequence of numbers in Mata
Date   Tue, 2 Oct 2007 10:41:59 +0200

You don't need a -seq()- function. See -help mata range()-.
ben

On 10/2/07, Le Wang <[email protected]> wrote:
> Hi there,
>
> I have another question in Mata that I couldn't figure out.
>
> Suppose that I want to generate a sequence of numbers, equally spaced
> between ajacent numbers.
>
> mata drop seq()
> real vector seq(real scalar from, real scalar to, real scalar increment)
> {
>         n=((to-from)+increment)/increment  /* Number of points*/
>
>         x=J(n,1,0)
>
>         for (i=1;i<=n;i++){
>                 x[i,.]=from+increment*(i-1)
>         }
>
>         return(x)
> }
>
>
>
> This function works well when the end points are integers, but fails
> otherwise. In particular, the last point is always missing when the
> end points are NOT integers. Compare the following codes:
>
> x=seq(4,11,1)
>
> x=seq(4.2,6.1,.1)
>
>
> Can anyone tell me where I am wrong here? Many thanks.
>
> Le
>
> --
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Le Wang, Ph.D.
> Minnesota Population Center
> University of Minnesota
> (o) 612-624-5818
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index