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: Using a for loop to generate a number list


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Using a for loop to generate a number list
Date   Mon, 13 Jan 2014 16:00:44 +0000

<>

No need to do this at all. -egen-'s -cut()- function will take a numlist.

But for future reference note

1.

numlist "0/10"
di r(numlist)

2.

If you want to this via a loop, you would need -foreach ... of ...-

foreach v of num 0/10 {
   local temp `temp' `v'
}

except that that is a poor method compared with using -numlist-.

Nick
[email protected]


On 13 January 2014 15:43, Wen Jun Jie

> I have a small question, considering the following code:
>
> local temp = "0 "
>
> foreach i in 1/10 {
>  local temp = `temp' + `i' + " "
> }
>
> What I hope to achieve is a number list 0 1 2 3 4 5 6 7 8 9 10 and I
> could use that in the cut function (e.g. cut(`temp')), however a few
> things happened:
>
> - I cannot cast the i to a string, I already tried using string(`i'),
> however this also doesn't work. Could someone demonstrate how one
> should do this and what I am doing wrong?
*
*   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