楼主: 冬日娃娃
1275 4

[其他] 急问一个数据处理的方法 [推广有奖]

  • 0关注
  • 0粉丝

本科生

62%

还不是VIP/贵宾

-

威望
0
论坛币
253 个
通用积分
0.0029
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1374 点
帖子
76
精华
0
在线时间
90 小时
注册时间
2007-8-18
最后登录
2013-3-14

楼主
冬日娃娃 发表于 2012-4-1 22:22:26 |AI写论文
15论坛币
现在我的数据结构是这样的:
number 食物1  数量1  单位1  食物2 数量2 单位2  食物3......
食物是用代码表示的,但每一个人吃的食物都不一样,故每个人的代码都不一样。单位是指两或斤或公斤,是用0,1,2表示的。
现在我有这些食物所含营养素的量,结构是这样的:
食物名称(代码表示)  蛋白质  热量  脂肪
.
.
.
.

问题是:想求出每个人摄入的蛋白质、热量和脂肪的量。如何做。

关键词:数据处理 Number 数据结构 蛋白质 NUM number 蛋白质 营养素 如何 数据分析专题 数据处理 数据分析软件 数据分析报告 面板数据分析 excel数据分析 数据分析方法 项目数据分析

沙发
hplcdadong 发表于 2012-4-2 01:24:40
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 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 1 + 1 + 1 Good.

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

藤椅
冬日娃娃 发表于 2012-4-2 11:00:45
hplcdadong 发表于 2012-4-2 01:24
1. Assume that your first database is "a", the data structure is " food1 amount1 unit1 food2 amount2 ...
merge的时候database a里食物代码会自动匹配database b里的吗。。。那merge完了的数据结构是怎样的呢

板凳
hplcdadong 发表于 2012-4-3 02:19:11
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

报纸
冬日娃娃 发表于 2012-4-4 14:12:06
非常感谢

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-24 02:45