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


雷达卡



京公网安备 11010802022788号







