I want to run a regression where the dependent variable is based on the group specified by one variable and the independent variables are all other variables apart from that. Here is an example dataset:
I figured out how to make the dependent variable:
How can I make a loop that runs a regression of dep_var against all remaining variables? For instance, in the first observation row, it regresses dep_var against var_1, var_2 and var_3 but in the second row, it regresses dep_var against var_1, var_3 and var_4, and so on. In my actual dataset, I have 20 groups and want to run combination of different regressions based on group type.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(var1 var2 var3 var4 group) 22 45 66 87 4 45 3 33 44 2 12 2 5 35 1 34 66 2 11 3 5 42 4 7 2 32 56 7 44 3 87 1 22 2 4 6 3 1 9 1 45 45 45 87 2 3 12 3 44 1 2 34 2 33 3 66 5 44 5 3 42 32 2 2 4 56 87 9 4 2 1 4 5 7 1 3 7 32 22 3 end
Code:
gen dep_var=. forval j=1/4{ replace dep_var = var`j' if group==`j' }
Comment