问题
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!
回答1:
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="_".
来源:https://stackoverflow.com/questions/52204173/change-rows-to-columns-based-on-key-ids