Change rows to columns based on key ID's

2019-08-15 05:47发布

So here's an example of what I have, and an explanation of what I am looking for. I can't seem to get the restructure function in SPSS to work properly, could be the wrong tool for the job. Any help would be appreciated. Thank you!

  • ID | Car_Make | Car_Model
  • 999, Subaru, WRX
  • 867, Volvo, 240
  • 999,Acura, TSX

  • ID | Car_Make1 | Car_Model1 | Car_Make2 | Car_Model2.....(Dependent on list)
  • 999, Subaru, WRX, Acura, TSX
  • 867, Volvo, 240

Any thoughts? Thank you!

标签: spss
1条回答
Evening l夕情丶
2楼-- · 2019-08-15 06:08

What you are missing is a key\index variable. Try this:

* first recreating your sample data.
data list list/ ID (f10) Car_Make  Car_Model (2a20).
begin data
999, "Subaru", "WRX"
867, "Volvo", "240"
999,"Acura", "TSX"
end data.

* now creating an index and restructuring.
sort cases by ID.
compute ind=1.
format ind(f2).
if $casenum>1 and ID=lag(ID) ind=lag(ind)+1.
casestovars /id=ID/index=ind/sep="_".
查看更多
登录 后发表回答