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

From |
"Le Wang" <statauser@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Generating a sequence of numbers in Mata |

Date |
Mon, 1 Oct 2007 20:21:20 -0500 |

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/

**Follow-Ups**:**Re: st: Generating a sequence of numbers in Mata***From:*"Ben Jann" <ben.jann@gmail.com>

- Prev by Date:
**Re: st: re: optional arguments in Mata** - Next by Date:
**st: re: generating a sequence of numbers in Mata** - Previous by thread:
**st: Can't size do-file editor window in Stata 10** - Next by thread:
**Re: st: Generating a sequence of numbers in Mata** - Index(es):

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