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

发布于 2024-09-30 08:19:07 字数 121 浏览 0 评论 0原文

在 SPSS 中编写这样的公式的最佳方法是什么:l(x)=l(x-1)-d(x-1) 其中 l(x) 是年龄组 x 面临风险的总人数; d(x) 是 x 年龄组的死亡总数。因此,d(x-1) 是 x-1 年龄组的总死亡人数。谢谢

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 risk 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长亭外,古道边 2024-10-07 08:19:07

我不确定我是否完全理解你的问题,但你也许可以利用 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文