变量的表转换

问题描述

我的数据集如下所示,但有更多品牌和类别。

enter image description here

我想转成品牌为一排,属性(质量好,价格实惠)在列

enter image description here

我尝试过 VARSTOCASES,我可以从中计算平均值,但这不是我想要的输出

我需要以某种方式拥有品牌名称 - 应将其从我的所有变量中撤回

compute brand=char.substr(brand,16)

喜欢

compute brand=char.substr(P1_Good_Quality_BMW,16)

我对varstocases部分没问题,然后我可以把我的输出像GQ一样放到列中,但不知道如何拥有所有的品牌名称并让它们匹配属性的平均值

预先感谢您的帮助

解决方法

这将获得您想要的结构中的数据 - 每个品牌占一行,每个属性占一列:

varstocases /make GQ from P1_GoodQuality_BMW P1_GoodQuality_Audi P1_GoodQuality_Mercedes
        /make Afford from P2_Affordable_BMW  P2_Affordable_Audi  P2_Affordable_Mercedes
       /index=brand(GQ).
* at this point you should have the table you were trying to create,* we'll just extract the brand names properly.
compute brand=char.substr(brand,16).
execute.
* now we have the data structured nicely,we can aggregate by brand.
dataset declare agg.
aggregate /out=agg /break=brand /GQ Afford = mean (GQ Afford).
dataset activate agg.