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/