如何在SPSS中编程l(x)= l(x-1)-d(x-1)?

时间:2010-11-04 17:41:13

标签: spss

在SPSS中对这样的公式进行编程的最佳方法是什么:l(x)= l(x-1)-d(x-1)其中l(x)是年龄组x的风险总人数; d(x)是年龄组x的死亡总数。所以,d(x-1)是年龄组x-1的总死亡人数。感谢

1 个答案:

答案 0 :(得分:1)

我不确定我是否完全理解您的问题,但您可以在SPSS中利用LAG功能。

查看下面的语法以获得一个想法:

*--------------------------------------------------------------------------------------------------.
* Lets create some fake data.
*--------------------------------------------------------------------------------------------------.
DATA LIST LIST (",") / id risk death.
BEGIN DATA  
1, 274, 123
1, 123, 34
1, 1235, 23
2, 3456, 231
2, 1897, 12
END DATA.

*--------------------------------------------------------------------------------------------------.
*  Create a basic lag to get the previous record's values.
*--------------------------------------------------------------------------------------------------.
COMPUTE risk.lag1 = LAG(risk, 1).
COMPUTE death.lag1 = LAG(death, 1).

*--------------------------------------------------------------------------------------------------.
*  Create a lag if group dependent -- assumes your cases are in the order you want
*  Only executes if the previous records value of ID is the same as the current record.
*--------------------------------------------------------------------------------------------------.
IF (id = LAG(id,1)) risk.lag2 = lag(risk,1).
IF (id=LAG(id,1)) death.lag2 =  lag(death,1).
EXECUTE.

*--------------------------------------------------------------------------------------------------.
*  ....And the data.....
*--------------------------------------------------------------------------------------------------.
LIST CASES.

为您提供以下数据计算....

      id     risk    death risk.lag1 death.lag1 risk.lag2 death.lag2

       1      274      123         .         .          .         .
       1      123       34       274       123        274       123
       1     1235       23       123        34        123        34
       2     3456      231      1235        23          .         .
       2     1897       12      3456       231       3456       231


Number of cases read:  5    Number of cases listed:  5