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]

st: RE: Using a for loop to generate a number list


From   "Cohen, Elan" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Using a for loop to generate a number list
Date   Mon, 13 Jan 2014 16:01:01 +0000

No need for any quotes, or to insert your own spaces:

loc tmp
forv i = 0/10 {
  loc tmp `tmp' `i'
}
di "`tmp'"


- Elan


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of J. J. W.
Sent: Monday, January 13, 2014 10:44
To: [email protected]
Subject: st: Using a for loop to generate a number list

Dear all,

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?

Thanks in advance!

Yours sincerely,

Wen Jun Jie
*
*   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/


*
*   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