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

st: scalars in loops


From   "Dimitriy V. Masterov" <dvmaster@lily.src.uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: scalars in loops
Date   Tue, 15 Jun 2004 17:27:36 -0500 (CDT)

Can someone please explain to me why one cannot use scalars to define the
upper bound in a range of a forvalues loop. A forvalues loop with a local
works,  a while loop with a scalar works, a while loop with a local works,
but not a forvalues loop with a scalar. There seems to be nothing in the
programming manual about this issue.

This is the code for the examples above:

tempname m1 m2

scalar `m1'=5
local `m2'=5


forvalues a=1(1)``m2'' {
	di "`a'"
}

local a=1
	while `a'<=``m2'' {
		di "`a'"
	local a=`a'+1
}


local a=1
	while `a'<=`m1' {
		di "`a'"
	local a=`a'+1
}

forvalues a=1(1)`m1' {
	di "`a'"
}

I am using Stata 8.2 SE with XP.


DVM

_______________________________________________________________________________
Dimitriy V. Masterov

Work:
Center for Social Program Evaluation
1155 East 60th St. Room 038
Chicago, IL 60637
Work: (773)256-6005
Fax: (773)256-6313

Home:
1312 East 53rd St., Apt.309
Chicago, IL 60615
Mobile: (773)220-2760



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index