I would like to do something which I believe is fairly simple, but I can't get the syntax correct. I would like to nest two for loops together, one which loops through a local variable and one which uses the value of the local to pull all the variables that start with that local.
My data contains, for example, the following columns:
B1_var1 B1_var2 B1_var3
B5_var1 B5_var2 B5_var3
...
The B1 variables come from the B1 table, B5 from B5 table, and so on.
I would like to loop through the variables by first referencing its table, and then running a regression for each variable which begins with the table prefix.
Code:
local tables "B1 B5 C3 C3A C5 C6" foreach table of local tables{ foreach var of varlist `table'_*{ reghdfe `var' shock, a(id year) cluster(id) } }
Thanks!
0 Response to Referencing local variable in nested foreach var of varlist
Post a Comment