请大家帮忙看看下面的问题,谢谢。
数据如下:
Firm  year  segment  weight
1         1          1           0.2
1         1          2           0.3
1         1          3           0.5
1         2            1         0.5
1          2           2         0.5
...
每一个公司年份有多个segment,所占比例是weight,每一个firm-year下segment 的个数是不同的,
现在想求每两个segment所对应的weight的乘积,并将所得结果生成新的变量,类似如下:
Firm  year  weight11 weight12  weight13 weight22 weight23 weight33
 1       1       0.04       0.06             0.1        0.09         0.15       0.25
 1       2        0.25        0.25           .            0.25         .                .
或者 生成如下形式也可以
Firm  year  weight_new        value
1          1          11                 0.04
1          1          12                0.06
...
谢谢赐教。