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

Re: st: while vs. forvalues


From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: while vs. forvalues
Date   Tue, 10 Aug 2004 00:44:52 -0400 (EDT)

Hm. How about -1/`n'- in the -forvalues- command? Does it work that way?
The primary reason it won't work the first way is if `n' is not specified
by the time you issue the -forval- command. You can also -set traceexpand
on- to see what's happening after the macros are expanded. Sometimes,
that's a lot of fun :).

Is there a type in your -while- command? `j ' would give you an empty
string. I am not even aware of ways to define a local macro that has a
space in its name. So it is the -while- way that should not work, at least
exactly the way you wrote it.

> 	I tried the following code snippet in a program, but I kept
> getting an "invalid syntax" error at the -forvalues- command (according
> to -trace-):
>
> 	forvalues j = 1(1)`n' {
> 		mat `newvec'[`n'-`j'+1,1] = `rowvec'[`j',1]
> 	}
>
> When I replaced that code with the following, the program completed as
> expected:
>
> 	local j = 1
> 	while `j '<= `n' {
> 		mat `newvec'[`n'-`j'+1,1] = `rowvec'[`j',1]
> 		local ++j
> 	}
>
> I'm puzzled by this, as my reading of p.214 of the User's Guide
> suggests these two approaches should be equivalent.  Any ideas?


 ---                                    Stas Kolenikov
 --       Ph.D. student in Statistics at UNC-Chapel Hill
 - http://www.komkon.org/~tacik/  -- [email protected]

* This e-mail and all attachments to it are not intended to provide any
* reasonable point of view and was transmitted to you in error. It
* should be immediately deleted by all recipients unless they really
* enjoy communicating with the author :). Other restrictions apply.

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