I'm currently want to let stata calculate P1 for each id and here is a formula: P1 = A11 * D1 + ... + A18 * D4iii
(A11 is the first value of A1 which equals 0.345865; A12 is the second value of A1 which equals 0.326931 ; A13 is the third one and so on)
For example, if I want to get the P1 for first person, here is the calculation:
0.345865 (A11) * 1.566901 (D1 for ID == 1) + 0.326931 (A12) * 0.233873 (D2i for ID == 1) ..... + 0.321616 (A18) * 1.384699 (D4iii)
I find it laborious and I wonder if there is any more convenient way to calculate P1 for other IDs automatically?
If I also want to calculate P2 for first person after calculating P1, P2 = A21 * D1 + .... + A28 * D4iii, do I need to use some syntax like for loop?
id | D1 | D2i | D2ii | D3i | D3ii | D4i | D4ii | D4iii | A1 | A2 |
1 | 1.566901 | 0.233873 | 0.286958 | 0.556992 | 1.113236 | 1.567941 | 1.490475 | 1.384699 | 0.345865 | -0.07561 |
2 | -0.39339 | -0.64672 | 0.07849 | -0.88745 | -0.2885 | -0.57468 | -0.70157 | -0.59344 | 0.326931 | 0.470004 |
3 | 0.390256 | 1.464312 | 1.263042 | 0.840091 | 0.97695 | -0.14107 | -0.23965 | -0.59344 | 0.320997 | 0.476968 |
4 | -0.69505 | -1.16996 | -1.51789 | -1.27133 | -1.12446 | -1.06964 | -1.0088 | -0.92313 | 0.367527 | 0.146237 |
5 | -0.86872 | 0.118493 | -0.1106 | 0.761692 | -0.67723 | 0.217444 | 0.459544 | 0.725319 | 0.376543 | 0.223233 |
6 | 0.387949 | -0.32069 | ||||||||
7 | 0.373703 | -0.36884 | ||||||||
8 | 0.321616 | -0.48557 |
0 Response to How to retrieve a specific value of a variable and calculate it with other values of variables?
Post a Comment