Changes vs week1

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

BZAK_04
Posts: 2
Joined: Thu Jan 16, 2014 1:48 pm

Changes vs week1

Postby BZAK_04 » Thu Jan 16, 2014 1:55 pm

Data file:

WEEK REGION PRODUCT SHARE
1 3 10 10
1 6 5 0.10
1 2 15 3
1 1 11 0.010
1 9 1 1.05

2 9 7 10
2 8 15 0.10
2 3 10 3
2 1 1 0.010
2 9 1 2.015

3 4 10 0.001
3 2 11 0.2
3 3 10 1.01
3 1 2 1.010
3 7 3 3.005

I need to create new variable using Share column wich will be equal:

IF (SAME_REGION AND SAME_PRODUCT) NEW_COLUMN=WEEK2-WEEK1. IF (REGION=3 AND PRODUCT=10) NEW_COLUMN=3-10.
IF (SAME_REGION AND SAME_PRODUCT) NEW_COLUMN=WEEK3-WEEK1. IF (REGION=3 AND PRODUCT=10) NEW_COLUMN=1.01-10.

or

IF (SAME_REGION AND SAME_PRODUCT) NEW_COLUMN=WEEK2-WEEK1. IF (REGION=3 AND PRODUCT=10) NEW_COLUMN=3-10.
IF (SAME_REGION AND SAME_PRODUCT) NEW_COLUMN=WEEK3-WEEK2. IF (REGION=3 AND PRODUCT=10) NEW_COLUMN=1.01-3.

So I need to show share changes vs week#1. Can you please advise how can I do this? Thank you.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Changes vs week1

Postby GerineL » Mon Jan 20, 2014 10:08 am

I am not quite sure what you want to do with this function, but I think these 2 things can help you:

Lag function: Get value from earlier row or next row.
You can also use this in combination with if-function, for instance:

if (week = lag(week)) -> if the value of week in this row is similar to that in the previous row.


aggregate - first : Give a variable the same value as the first one (first sort cases, then have break on week, then it gets the value of the first value for that week).
BZAK_04
Posts: 2
Joined: Thu Jan 16, 2014 1:48 pm

Re: Changes vs week1

Postby BZAK_04 » Mon Jan 20, 2014 9:20 pm

Thank you Gutnre for response.

I have data file with MarketShare variable in one column. I need to show the share change vs first week of the year and share change vs previous week. I am trying to find the way how to create new variable with changes only. I cannot use LAG command because I don’t know how many cases I will have per one week. There will be one million or more cases in data file by the end of the year.

It’s very easy to do in excel – just to run table using week and marketshare variables in spss, to resave it in excel then calculate changes using formulas, then to run line graphs. But I would like to find the way how to do this in spss.

I am working on this...
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Changes vs week1

Postby GerineL » Tue Jan 21, 2014 10:18 am

if the problem is you have different weeks per file, you can add a part to your syntax indicating whether it is the same week or not using lag function

if (week = lag(week))

Who is online

Users browsing this forum: No registered users and 2 guests

cron