Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: Re: st: looping from 1 to a number defined by a scalar


From   "Steichen, Thomas J." <SteichT@rjrt.com>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: Re: st: looping from 1 to a number defined by a scalar
Date   Thu, 27 Dec 2007 15:48:42 -0500

Tom's code is correct; the = is required:

scalar ng = 6
forvalues i=1/`=ng' {
   di `i'
}
1
2
3
4
5
6

However, the code Nicola claimed to work, cannot:

forvalues 1/6 {
   di `i'
}
invalid syntax
r(198);

Since the problem is not the forvalues loop, it must be the code within the loop. I suggest setting -trace on- to see where it blows out and/or manually performing each matrix line to find the syntax problem.

Tom

-----------------------------------
Thomas J. Steichen
steicht@rjrt.com
-----------------------------------

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2..harvard.edu] On Behalf Of Kabir Chabal
Sent: Thursday, December 27, 2007 3:33 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: Re: st: looping from 1 to a number defined by a scalar

Drop the leading "=" before the ng in Tom's code:

scalar ng = 63
forvalues i=1/`ng' {
    ...

}

On 12/27/07, nicola.baldini2@unibo.it <nicola.baldini2@unibo.it> wrote:
> Same error.
>
> Nicola
>
> At 02.33 25/12/2007 -0500, "Tom Trikalinos" wrote:
> >Subject: Re: st: looping from 1 to a number defined by a scalar
> >
> >try e.g.
> >
> >
> >
> >scalar ng = 63
> >forval i=1/`=ng' {
> >      // code
> >      noi di " `i'. " _c
> >}
> >
> >
> >tom
> >
> >
> >
> >On Dec 24, 2007 12:15 PM,  <nicola.baldini2@unibo.it> wrote:
> >> I would like to create a loop from 1 to a number defined by a scalar, but:
> >> . forvalues 1/ng {
> >>   2.    mat p=inv((r1+vu)/ns[`i'])*r1
> >>   3.    mat q=r2*(idd-p)
> >>   4.    mat xtilde`i' = xmean*p +mux3*(idd-p)+dz*q
> >>   5.    }
> >> invalid syntax
> >> r(198);
> >>
> >> However, ng = 63 so that the following works:
> >> . forvalues 1/63 {
> >>   2.    mat p=inv((r1+vu)/ns[`i'])*r1
> >>   3.    mat q=r2*(idd-p)
> >>   4.    mat xtilde`i' = xmean*p +mux3*(idd-p)+dz*q
> >>   5.    }
> >>
> >> Anything shorter than...?
> >> local i = 0
> >> while `i' < ng {
> >>   2.    local i = `i' + 1
> >>   3.    mat p=inv((r1+vu)/ns[`i'])*r1
> >>   4.    mat q=r2*(idd-p)
> >>   5.    mat xtilde`i' = xmean*p +mux3*(idd-p)+dz*q
> >>   6.    }
> >>
> >> Merry Xmas,
> >> Nicola
>
> *
> *   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/
>
*
*   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/

-----------------------------------------
CONFIDENTIALITY NOTE: This e-mail message, including any
attachment(s), contains information that may be confidential,
protected by the attorney-client or other legal privileges, and/or
proprietary non-public information. If you are not an intended
recipient of this message or an authorized assistant to an intended
recipient, please notify the sender by replying to this message and
then delete it from your system. Use, dissemination, distribution,
or reproduction of this message and/or any of its attachments (if
any) by unintended recipients is not authorized and may be
unlawful.   

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