Dear all,

it might be a wood for the trees kind of problem, but I cannot wrap my head around it.
I have two datasets, one where the observations are seconds and variables are a score for each second for a person:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double(Sec PersonA) str7 PersonB double PersonC str7 PersonD
12 2 "4" 2 "4"
13 4 "4" 4 "4"
14 4 "2" 4 "2"
15 4 "4" 4 "4"
16 4 "3" 4 "3"
17 3 "3" 3 "3"
18 3 "2" 3 "2"
19 3 "1" 3 "1"
20 3 "2" 3 "2"
21 5 "3" 5 "3"
22 5 "4" 5 "4"
23 5 "5" 5 "5"
24 5 "5" 5 "5"
25 4 "5" 4 "5"
end
(All values are numeric, I got this wrong in my example).

What I did before was this: egen mean=rowmean( PersonA- PersonD ). But now it got trickier:


Another data set contains information about each of these persons, on the basis of which the mean for each second of all persons is to be weighted. In my example data, my goal would be to eaven out values based on kind of car and pet. Unfortunately, every person is a case here, so I can't just match the sets and create a variable for weighting.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str7 PersonID double(car Pet)
"PersonA" 1 2
"PersonB" 2 4
"PersonC" 1 4
"PersonD" 1 4
end
Can anyone think of a smart way to work my way around?The dataset is one of many and contains data for thousands of seconds and many persons.
As always, thankful for every suggestion and many thanks in advance!

Best
N.