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]

From |
Nabin Kafle <nkafle89@gmail.com> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Defining upper limit of loop |

Date |
Wed, 11 Dec 2013 16:30:52 -0600 |

I want to loop a cycle number of times indicated by a number in a variable name. For example: X Y Z 1 2 1 2 3 4 3 2 2 3 2 2 4 2 2 . . . . gen sum=X forvalues i=1/"Z" { replace sum=X+X[_n+`i'] } What would be other way to do such if it is not possible by -forvalues- command. On Wed, Dec 11, 2013 at 4:18 PM, Thomas, Anthony <anthony_h_thomas@brown.edu> wrote: > Stata probably will not let you do that. Variable names cannot be a > number, and "forval" type loops expect a numeric range (i.e. "variable > name" would have to be a number). If you want to use variables in a > loop, consider using: > > foreach i of varlist "varlist"{ > > commands > > } > > Anthony > > On Wed, Dec 11, 2013 at 5:08 PM, Nabin Kafle <nkafle89@gmail.com> wrote: >> Is there a way that I can use the forvalues command in stata in a way >> that I upper value of the loop can be defined from the varibale list. >> >> forvalues i = 1/"var name" { >> code for loop >> * >> * 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/ -- Nabin Kafle * * 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/

**Follow-Ups**:**Re: st: Defining upper limit of loop***From:*Sergiy Radyakin <serjradyakin@gmail.com>

**Re: st: Defining upper limit of loop***From:*"Thomas, Anthony" <anthony_h_thomas@brown.edu>

**References**:**st: Defining upper limit of loop***From:*Nabin Kafle <nkafle89@gmail.com>

**Re: st: Defining upper limit of loop***From:*"Thomas, Anthony" <anthony_h_thomas@brown.edu>

- Prev by Date:
**Re: st: dialog program: make LISTBOX initially hidden or use repopulate?** - Next by Date:
**Re: st: Defining upper limit of loop** - Previous by thread:
**Re: st: Defining upper limit of loop** - Next by thread:
**Re: st: Defining upper limit of loop** - Index(es):