将不同形状的 table 的值附加到一个 table
Attach values to one table from a differently shaped table
所以我有一个从养蜂人调查中收集的数据集,看起来像这样:
[Table 1]
ID | Crop | Year | Hives | HoneyP | CropP |
----+------+------+-------+--------+-------+
1 2 2014 2391 . .
2 4 2008 136 . .
3 12 2019 12346 . .
| |
V (and so on...) V
我还有一个时间序列的农作物价格电子表格,例如
[Table 2]
Year | Crop1 | Crop2 |
-----+-------+-------+
2008 .56 .45
2009 .42 .64 ->
2010 .69 .68 (and more crops) ->
2011 .62 .05 ->
...
是否可以在 PSPP/SPSS 中迭代 Table 1 中的观察值,并根据年份和作物将 Table 2 中的值插入到 CropP
变量中标识符?
这就是我在伪代码中的想象:
for each obs:
obs.CropP = Table2[obs.Year][obs.Crop]
我还有其他属性要添加到观察结果中(例如价格指数),但它们都是一维的,必要时可以手动输入;如果我可以在调查年度以编程方式添加农作物的价格,那将节省大量时间和麻烦。
我建议重塑而不是迭代。
假设您已将 table 都读入 SPSS,并且数据集称为 table1
和 table2
- 请执行以下两个步骤:
首先您需要重塑农作物价格数据以适应主数据集:
dataset activate table2.
varstocases /make cropPR from crop1 to cropX/index=crop(cropPR).
*your crop index now is a string like "crop3" and needs to be turned into a number.
compute crop=char.substr(crop,5,5).
alter type crop (f5).
sort cases by year crop.
现在这个 table 已准备好附加到您的主要数据。
dataset activate table1.
sort cases by year crop.
match files /file=* /table=table1 /by year crop.
exe.
所以我有一个从养蜂人调查中收集的数据集,看起来像这样:
[Table 1]
ID | Crop | Year | Hives | HoneyP | CropP |
----+------+------+-------+--------+-------+
1 2 2014 2391 . .
2 4 2008 136 . .
3 12 2019 12346 . .
| |
V (and so on...) V
我还有一个时间序列的农作物价格电子表格,例如
[Table 2]
Year | Crop1 | Crop2 |
-----+-------+-------+
2008 .56 .45
2009 .42 .64 ->
2010 .69 .68 (and more crops) ->
2011 .62 .05 ->
...
是否可以在 PSPP/SPSS 中迭代 Table 1 中的观察值,并根据年份和作物将 Table 2 中的值插入到 CropP
变量中标识符?
这就是我在伪代码中的想象:
for each obs:
obs.CropP = Table2[obs.Year][obs.Crop]
我还有其他属性要添加到观察结果中(例如价格指数),但它们都是一维的,必要时可以手动输入;如果我可以在调查年度以编程方式添加农作物的价格,那将节省大量时间和麻烦。
我建议重塑而不是迭代。
假设您已将 table 都读入 SPSS,并且数据集称为 table1
和 table2
- 请执行以下两个步骤:
首先您需要重塑农作物价格数据以适应主数据集:
dataset activate table2.
varstocases /make cropPR from crop1 to cropX/index=crop(cropPR).
*your crop index now is a string like "crop3" and needs to be turned into a number.
compute crop=char.substr(crop,5,5).
alter type crop (f5).
sort cases by year crop.
现在这个 table 已准备好附加到您的主要数据。
dataset activate table1.
sort cases by year crop.
match files /file=* /table=table1 /by year crop.
exe.