gpt4 book ai didi

spss - 使用 SPSS 以编程方式在案例之间复制数据

转载 作者:行者123 更新时间:2023-12-01 08:03:22 29 4
gpt4 key购买 nike

对于一个学校项目,我发现自己正在使用人口普查局当前人口调查中的数据。我选择了 SPSS 来处理数据,因为在我有限的时间范围内,它似乎是最容易直接使用的软件。一切看起来都很简单,除了一个给我带来麻烦的操作。

对于我的数据集中的每个案例——每个案例代表一个被调查的个体——定义了以下(相关)变量:

  • 家庭 ID (HHID)——每个受访家庭的唯一编号
  • 个人 ID (PID)——家庭中每个人的唯一编号
  • 此人的年龄 (AGE)
  • 此人是否获得公共(public)健康保险——0 或 1 (HASHEALTH)
  • 个人父亲的个人 ID,如果家庭中存在(如果不存在则为 0)(POPNUM)
  • 个人母亲的个人 ID,如果家庭中有母亲(如果不存在则为 0)(MOMNUM)

这就是问题所在:我需要将任何给定 parent 的 KIDHASHEALTH 值设置为最年轻的人的 HASHEALTH 值,其 HHID 和 POPNUM 或 MOMNUM 值与当前案例的 HHID 和 PID 匹配——功能上,他们最小的 child 。

到目前为止,我一直无法弄清楚如何使用 SPSS 语法来执行此操作。任何人都可以想出一种方法来完成我正在尝试做的事情,无论是使用语法还是其他方式?

非常非常感谢。

使用示例数据编辑:

HHID |PID |AGE |POPNUM |MOMNUM |HASHEALTH |KIDHASHEALTH
-----+----+----+-------+-------+----------+------------
1 |1 |45 |0 |0 |0 |0 //KIDHASHEALTH == 0 because
1 |2 |48 |0 |0 |0 |0 //youngest child's HASHEALTH == 0
1 |3 |13 |1 |2 |0 |0
2 |1 |33 |0 |0 |0 |1 // == 1 because youngest child's
2 |2 |28 |0 |0 |0 |1 // HASHEALTH == 1
2 |3 |15 |1 |2 |0 |0
2 |4 |12 |1 |2 |1 |0
-----+----+----+-------+-------+----------+------------

最佳答案

下面的代码仅在您的小数据片段上进行了测试。因此,不能保证所有具有其特性的数据。该代码假设 AGE 是整数。

*Let's add small fractional noise to those children AGE who HASHEALTH=1.
*In order to insert the info about health right into the age number.
if hashealth age= age+rv.unif(-.1,+.1).

*Turn to fathers. Combine POPNUM and PID numbers in one column.
compute parent= popnum. /*Copy POPNUM as a new var PARENT.
if parent=0 parent= pid. /*and if the case is not a child, fill there PID.
*Now a father and his children have the same code in PARENT
*and so we can propagate the minimal age in that group (which is the age of the
*youngest child, provided the man has children) to all cases of the group,
*including the father.
aggregate /outfile= * mode= addvari
/break= hhid parent /*breaking is done also by household, of course
/youngage1= min(age). /*The variable showing that minimal age.
*Turn to mothers and do the same thing.
compute parent= momnum.
if parent=0 parent= pid.
aggregate /outfile= * mode= addvari
/break= hhid parent
/youngage2= min(age). /*The variable showing that minimal age.
*Take the minimal value from the two passes.
compute youngage= min(youngage1,youngage2).

*Compute binary KIDHASHEALTH variable.
*Remember that YOUNGAGE is not integer if that child has HASHEALTH=1.
compute kidhashealth= 0.
if popnum=0 and momnum=0 /*if we deal with a parent
and age<>youngage /*and the youngage age listed is not their own
and rnd(youngage)<>youngage kidhashealth= 1. /*and the age isn't integer, assign 1.
compute age= rnd(age). /*Restore integer age
exec.
delete vari parent youngage1 youngage2 youngage.

关于spss - 使用 SPSS 以编程方式在案例之间复制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19458191/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com