## Coding a complicated formula

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

MarcusHue
Posts: 2
Joined: Thu Sep 25, 2014 8:48 am

### Coding a complicated formula

Hello SPSSForum,

I recently started to work frequently with SPSS and so far I got well around just with searching the internet for solutions. But now I am at a problem where I don't even now how to google it. Therefore I am mainly asking for hints where I can find material how to teach myself. However here is the problem description where I got stuck.

I have a big Database with the following variables:
- Country_i -> Domestic country
- Country_j -> Destination country
- Psy_Dist_1 ->Psychic Distance 1st Dimension
- Psy_Dist_2 ->Psychic Distance 2nd Dimension
- Psy_Dist_3 ->Psychic Distance 3rd Dimension
- Psy_Dist_4 ->Psychic Distance 4th Dimension
- Psy_Dist_5 ->Psychic Distance 5th Dimension

From the five dimensions of Psychic Distance I have to calculate now one composite index with the formular

|k=1 to 5| sum (( Psy_Dist_ijk)^2 /V_ik /5)
where
i is the fist country
j the second country
k the kth dimension of psychic distance.
V_ik is the variance for the Psychic distance of the kth dimension and th ith country across all j countries

Especially including the calculation of V_jk is something I don't know how to start.

Some hints for tutorials or anything like that would be awesome

Thank you in advance and best regards
Marcus
Erikyo
Posts: 28
Joined: Mon Mar 30, 2009 8:20 pm

### Re: Coding a complicated formula

Not easy indeed !

Not sure I have the right solution but this may help !

Starting with this : sum (( Psy_Dist_ijk)^2 /V_ik /5)
I would create 3 variables ...

- A first variable that does this part : sum (( Psy_Dist_ijk)^2
- A second variable that calculate the variance : V_ik
- And a third variable that devide your first new variable by your second and then by 5 !

That's how I would tackle this !
MarcusHue
Posts: 2
Joined: Thu Sep 25, 2014 8:48 am

### Re: Coding a complicated formula

First part is no problem (not even syntax is needed )
For the second part I need 5 variables as I have five dimensions from which I need the variance. That shouldn't be a problem.

Where I get stuck is the following: I have 14400 cases (120 country_i * 120 country_j) and the variance I need is something like this

Variance of Psy_Dist_1 when country_i = Afghanistan
Variance of Psy_Dist_1 when country_i = Algeria
Variance of Psy_Dist_1 when country_i = Austria
.
.
.
Variance of Psy_Dist_1 when country_i = Zimbabwe

So each of the 120 variances I need, I only need for 120 cases when country_i is the same. But I don't really want to do that by hand

### Who is online

Users browsing this forum: No registered users and 2 guests