将t-1处的记录值分配给所有情况

问题描述 投票:1回答:1

我有一个有关足球运动员转会的数据集,其中包含诸如转会年(1992-2019)和转会费的变量。我能够将每个球员的每年最高转会费作为变量来计算,但无法弄清楚如何将t-1处的转会记录作为变量。

[例如,如果球员X在2019年被转会,转会记录(最高转会费)是在2017年产生的,则其变量应显示该费用(t-1)。如果球员Y在2015年被转会,而当时的记录是从2012年开始的,那么应该将2012年的转会费作为一个变量。

Here's a link to a sample image

spss
1个回答
0
投票

这里是一种语法,它会逐步理解,很容易理解。它可能可以用更综合的方式编写,但让可读性成为优先事项:

* Sort the cases in chronological order, for each player, as we will parse the records one by one.
sort cases by name year (A).

* create the MAX_FEE variable, and assign a starting value.
compute MAX_FEE=0.
* $casenum will help us navigate through the records. Combined with the LAG function (which by default looks into the previous record) we are simulating a record by record parsing.
* start with the first record.
if $casenum=1 MAX_FEE=fee_cleaned.

* then move onto the others.
do if $casenum>1.
    *setting the initial MAX_FEE for the first transfer of a player (i.e. - the name changes, compared to previous record).
    if name<>lag(name) MAX_FEE=fee_cleaned.
    * for the same player, comparing the current transfer's fee with the current MAX_FEE (i.e. - the MAX_FEE from the previous record).
    if name=lag(name) and fee_cleaned > lag(MAX_FEE) MAX_FEE=fee_cleaned.
    if name=lag(name) and fee_cleaned <= lag(MAX_FEE) MAX_FEE=lag(max_fee).
end if.
EXECUTE.
© www.soinside.com 2019 - 2024. All rights reserved.