Indirect referencing between records.

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

Posts: 5
Joined: Mon Oct 17, 2011 1:44 pm

Indirect referencing between records.

Postby tathta » Thu Oct 27, 2011 4:01 pm

I'm a new SPSS user, and have a slightly odd-ball problem that I'm trying to code…

I need to define one variable based on the values within a different record.

To make this more concrete, here is the example of what I want to do:
> The dataset starts with two variables: Date and Todays_Rainfall.
> I would like to create a new variable called Yesterdays_Rainfall.
> Yesterdays_Rainfall will equal the value in Todays_Rainfall from the record that has a date one day prior.

In more general terms:
> For the ith record: Yesterdays_Rainfall[Date=i] = Todays_Rainfall[Date=i-1]
> I just need to know how to do the indirect referencing, after that I can figure out the looping to make SPSS do what I'm looking for.

A couple notes:
1) The example above is my most simple example. I have about a dozen variables that need to be defined this way, some are direct copies while others are more complicated (averages over the past week, values from the previous wednesdays, etc etc)
2) I want this as a script, because the code will be reused approx yearly and manual cut-pasting is time consuming.
3) One workaround *could* be to use excel, but I don't want to because Excel is icky.
4) A better workaround *could* be to create dummy datasets and then merge them. But this introduces many opportunities for things to go wrong if I have to do it a half-dozen times… This is my back-up solution, but I'd much prefer a more direct and elegant solution.

Any thoughts?
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Indirect referencing between records.

Postby GerineL » Fri Oct 28, 2011 2:03 pm

depends a bit on how your data is organized in your file.

if you have


you can simply use a lag, but if it is organized differently you might not be able to do that...

Who is online

Users browsing this forum: No registered users and 1 guest