【问题标题】:Reshaping when variables are not unique变量不唯一时的重塑
【发布时间】: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


    【解决方案1】:

    您的reshape 命令适用于您的数据示例,只要您为item 使用适当的类型。

    input int id str11  item float consumption 
    

    使用str7 只会截断描述并导致虚假重复。

    【讨论】:

      猜你喜欢
      • 2016-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      相关资源
      最近更新 更多