Dear fellow Stata users,
I'm trying to assign weights to some variables in my dataset to compute a weighted sum but I can't figure out how. I have a variable of weights. The weight in the first row (1.1) should be assigned to v1, the weight in the second row (3.4) to v2, etc. So then I'm able to compute a weighted sum, which for the first observation would be equal to 4*1.1 + 0*3.4 + 1*3.5 + 2*2.3 , and for the second 3*1.1 + 0*3.4 + 4*3.5 + 3*2.3
I hope I made myself clear.
Thanks in advance.
I'm trying to assign weights to some variables in my dataset to compute a weighted sum but I can't figure out how. I have a variable of weights. The weight in the first row (1.1) should be assigned to v1, the weight in the second row (3.4) to v2, etc. So then I'm able to compute a weighted sum, which for the first observation would be equal to 4*1.1 + 0*3.4 + 1*3.5 + 2*2.3 , and for the second 3*1.1 + 0*3.4 + 4*3.5 + 3*2.3
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(v1 v2 v3 v4 unweighted_sum) float weights 4 0 1 2 7 1.1 3 0 4 3 10 3.4 2 0 7 4 13 3.5 1 10 5 7 23 2.3 2 0 1 5 8 . 1 0 0 9 10 . 2 3 5 0 10 . 11 4 6 0 21 . end
I hope I made myself clear.
Thanks in advance.
Comment