Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Evaluating an expression in -forvalues-


From   "Richard Upward" <[email protected]>
To   <[email protected]>
Subject   st: Evaluating an expression in -forvalues-
Date   Tue, 16 Dec 2003 09:55:01 +0000

Dear Statalisters

I'm trying to write some code that repeats a varying number of times, based on an argument `t'.  I'd like to be able to write, for example

forvalues i = 1(1)`t'+2 {
               <some code>
               }

but -forvalues- does not seem to allow this because it evaluates `t' but does not add it to the 2.  So, if `t' was 10 I end up with

forvalues i=1(1)10+2

which gives a syntax error.  Is there a way to force -forvalues- to evaluate an expression like this, or do I need to set another macro equal to `t'+2 before the loop?  That seems a bit clunky.  I noticed that I can use an expression like this in a -while- loop.

Thanks for any help

Richard

Richard Upward
School of Economics
University of Nottingham
University Park
Nottingham NG7 2RD
Tel: +44 (0) 115 95 14735

http://www.nottingham.ac.uk/economics/staff/details/richard_upward.html


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



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