开发者

how to program l(x)=l(x-1)-d(x-1) in SPSS?

What is the best way to program formula like this in SPSS: l(x)=l(x-1)-d(x-1) where l(x) is total number of people at ris开发者_Python百科k at age group x; d(x) is total number of death at age group x. so, d(x-1) is the total deaths at age group x-1. thanks


I am not sure if I fully understand your question, but you might be able to leverage the LAG function in SPSS.

Check out the syntax below to get an idea:

*--------------------------------------------------------------------------------------------------.
* 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.

Gives you the following data calculations....

      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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜