【发布时间】:2021-11-22 18:21:09
【问题描述】:
我在下面有一个数据集,我想在 Stata 中重塑它。
clear
input int id str7 item float consumption
1 "food123" 0.72
1 "food174" 0.51
1 "food167" 0.76
1 "food160" 0.02
1 "fruit240" 0.52
1 "fruit263" 0.06
1 "fruit254" 100.00
1 "drink345" 0.25
1 "drink340" 0.60
1 "vegtable466" 0.87
1 "vegtable440" 0.44
2 "food123" 0.26
2 "food167" 0.52
2 "food120" 0.44
2 "food160" 0.16
2 "fruit240" 0.09
2 "fruit242" 0.65
2 "fruit263" 0.80
2 "fruit230" 0.60
2 "fruit254" 0.32
2 "drink340" 0.90
2 "drink345" 0.05
2 "vegtable466" 0.24
2 "vegtable460" 0.78
end
结果是(行是id,列是items):
当我使用reshape 时,它显示“变量item 的值在id 中不是唯一的”。
我的代码是:
reshape wide consumption, i(id) j(item) string
我该怎么做?
【问题讨论】:
标签: statistics stata reshape stata-macros