Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: For loops, If Statements and Delimiters

From   Ryan Stevens <>
Subject   st: For loops, If Statements and Delimiters
Date   Mon, 11 Feb 2013 14:30:48 -0500

Hi all,

I have been having an issue with using for loop and if statements
together with a semi-colon delimiter. The following is some example
code for the problem I've come across:

# delimit ;
local j = 1;
foreach x of varlist var1-var3{;
       forval i = 1/12{;
                 replace `x' = `x'[`i']-`x'[`j'] in `i';
                 local j = `j' + 1;
                 replace `x' = `x'[`i']-`x'[`j'] in `i';
                 local j = 3;

Whenever I try running this I get an error on my if statement, where
Stata interprets "< 3" as a variable name. Any suggestions for loops
and if statements using delimiters would be greatly appreciated.

Thanks for your time,
Ryan Stevens
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index