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

From |
"Ben Jann" <ben.jann@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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 <statauser@gmail.com> 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/

**References**:**st: Generating a sequence of numbers in Mata***From:*"Le Wang" <statauser@gmail.com>

- Prev by Date:
**Re: st: Optional arguments in Mata** - Next by Date:
**st: RE: Do 2sls, ivreg etc. test the rank condition of identification?** - Previous by thread:
**st: Generating a sequence of numbers in Mata** - Next by thread:
**st: re: generating a sequence of numbers in Mata** - Index(es):

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