Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: forval question again


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   Re: st: RE: forval question again
Date   Wed, 11 Feb 2009 19:48:24 +0100

<>
What Rike wanted, was possible all along, w/o -local-s...

***********
sysuse auto, clear
forv i=`=mpg[1]'/`=turn[1]'{
di in red `i'
}
***********

HTH
Martin _______________________ ----- Original Message ----- From: "Rike" <[email protected]>
To: <[email protected]>
Sent: Wednesday, February 11, 2009 7:26 PM
Subject: Re: st: RE: forval question again


Howie's idea worked. Thanks everyone.

On 2/11/09, Howard Lempel <[email protected]> wrote:
This is probably not the most concise code.  That being said, try:

local start = start_year[1]
local end = end_year[1]

forval `start'/`end' {
do stuff
}

Hope this helps.
Howie



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Rike
Sent: Wednesday, February 11, 2009 1:06 PM
To: statalist
Subject: st: forval question again

Dear all,

this is a follow up question on the one right below.

I have tried

 forval x = start_year[1]/end_year[1] {

 }


but it gives me the invalid syntax error.

As for using r(min) and r(max) as per Martin's suggestion, I don't
think it will work because start_year and end_year are two different
variables. Any other ideas? Here is my question again:

I want forval to loop over the (min) value of two variables. More
specifically, there is a variable called start_year and another called
end_year and what I want is something like this:

forval x = start_year / end_year  {
.
.
}

The variables have all the same value but i want to repeat the same
codes across different samples that have varying starting and ending
years. This is why I don't want to put the years in numbers as this
would create a lot more work.

Is there a way to do this?

Thanks in advance.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/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/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/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/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