1. Assume that your first database is "a", the data structure is " food1 amount1 unit1 food2 amount2 unit2 food3 ...
2. Assume that your second database is "b", the data structure is "food protein energy fat"
use a, clear
gen person_id=_n
reshape long food amount unit, i(person_id) j(group)
merge m:1 food using b, nogenerate keep(match)
gen total_protein=proten*unit*amount //this is my good guess, you can use your own formula
gen total_energy=energy*unit*amount
gen total_fat=fat*unit*amount
sort id group
save a_b_combine, replace
collapse (sum) total_protein total_energy total_fat, by(person_id)
save results, replace //you should be allset
1) Yes if you use the same codes for food in your two databases (such as 1 for orange, 2 for banana,...)
2)After merging, the data structure should still be in long format like this:
person_id group food amount unit protein energy fat