HI,

I am encountering error while running a loop in stata. The following is my code

HTML Code:
forvalues i = 1/`MaxLPLags' {

  foreach var in state_gdp state_exp TE_shock {

    gen bad`var'`i' = L`i'.`var'*`state'
    gen good`var'`i' = L`i'.`var'*(1-`state')
 
  }
}
I have declared state, MaxPLags, as locals. When I run this loop, I come across

HTML Code:
invalid syntax
r(198);
I am not sure why I am getting this error. Some help is appreciated.
Thank you.

Regards
Indrani