I am trying to run a regression loop that loops over different treatment variables and if conditions based on the treatment variable, but am running into what I think is a syntax issue with my code.
Please see a (trivial) example that illustrates the problem below.
The code stops after one regression, giving the error message: ">3 invalid name; r(198)".
Any help on this would be much appreciated!
Please see a (trivial) example that illustrates the problem below.
Code:
* Load data sysuse auto, clear * Set up local for treatment variables local trt_var_list mpg headroom trunk * Set up local for condition list local cond1 "if foreign != ." local cond2 "if `trt' > 3" *** Run analysis loop * Loop over treatments foreach trt in `trt_var_list' { * Loop over if conditions forvalues i=1/2 { * Run regression reg price `trt' `cond`i'' } }
Any help on this would be much appreciated!
Comment