上面的数据,因为每一个公司代码(第一列)对应的变量 “分类”包含的内容不同,比如第一个公司代码,有5个分类,第二个公司代码,只有4个分类,而且分类还和第一个公司不一样。我想把他变形成下面的理想样子
公司代码 分类1(5015) 分类2(5020) 分类3(0) 分类4(5025) 分类5(5099) 分类6(5025)
"000001" 639 3871 7737 2283 895 0
最后一列分类6其实是补齐的,因为这家代码公司下,根本没有这个类别的数据,所以补上了变量,并填上了0
使用命令reshap无法完成任务,gather和spread之类的一样不行
reshape wide 取值1 取值2,i( code ) j( 分类 )
(note: j = 0 5005 5010 5015 5020 5025 5030 5050 5060 5099)
values of variable 分类 not unique within code
Your data are currently long. You are performing a reshape wide. You specified i(code) and
j(分类). There are observations within i(code) with the same value of j(分类). In the long
data, variables i() and j() together must uniquely identify the observations.
long wide
+---------------+ +------------------+
| i j a b | | i a1 a2 b1 b2 |
|---------------| <--- reshape ---> |------------------|
| 1 1 1 2 | | 1 1 3 2 4 |
| 1 2 3 4 | | 2 5 7 6 8 |
| 2 1 5 6 | +------------------+
| 2 2 7 8 |
+---------------+
Type reshape error for a list of the problem variables.