I have a dataset that looks like this:
I want to create a new variable
x_dot_y=weight1_a*weight2_a+ weight1_b*weight2_b+weight1_c*weight2_c
This may sound straightforward, but I have a very large number of weight variables (40000) so I would appreciate if someone can share any idea on how to write this in a more compact way.
I tried foreach but I am not able to get the list of a, b , c correct or so as it yields an incorrect value.
Any help is highly appreciated.
year | id | weight1_a | wight1_b | weight1_c | weight2_a | weight2_b | weight2_c | ||
2020 | 1 | 0.1 | 0.2 | 0.7 | 0.4 | 0.3 | 0.3 | ||
2020 | 2 | ||||||||
2020 | 3 | ||||||||
2020 | 4 | ||||||||
x_dot_y=weight1_a*weight2_a+ weight1_b*weight2_b+weight1_c*weight2_c
This may sound straightforward, but I have a very large number of weight variables (40000) so I would appreciate if someone can share any idea on how to write this in a more compact way.
I tried foreach but I am not able to get the list of a, b , c correct or so as it yields an incorrect value.
Any help is highly appreciated.
Comment