Trying to recode a variable dependent on values in others

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

gimmemoore
Posts: 2
Joined: Thu Feb 06, 2014 4:16 pm

Trying to recode a variable dependent on values in others

Postby gimmemoore » Thu Feb 06, 2014 4:56 pm

Hi everyone,

I am quite a beginner and am having real issues with what is probably straightforward.

I need to recode a variable under certain conditions based on what's in other ones.

Specifically, it's like this:

serial RECD RECM RECY INTD INTM INTY
1 77 77 7777 77 77 7777
2 9 9 2008 28 8 2008
3 20 10 2008 99 99 2008
4 77 77 7777 77 77 7777

(sorry for shortened formatting in above table, not sure how to fix!)


REC stands for 'form received date' and INT is 'interview date', D/Y/M is day/month/year


I need to recode INTM (month of interview), only when it is 99, based on what is in RECD and RECM.


If RECD is less than 6, i need to recode INTM to one less than RECM (i.e. if the interview report form was received in the first five days of the month, then set the interview month to the previous month.)

If RECD is 6 or greater, i need to set INTM to the same as RECM (i.e. the interview form was received the same month the interview took place.)

So in the example above, for serial no. 3 i want to recode INTM from 99 to 10, because RECM is 10 and RECD is greater than 5.

I've tried lots of things, but am getting nowhere trying to select INTM=99 and then RECODE under the various conditions. The order of commands and the syntax is getting me confused. Don't even know if i need a RECODE in there or not.

Trying things like:

if (INTM eq 99) and (RECD gt 5).
recode INTM=RECM.

or something like

if (INTM eq 99) and (RECD gt 5) and (RECM eq 1) INTM eq 1.

But no good.

Any help greatly appreciated!

Thanks,

Adam
apeape
Posts: 56
Joined: Mon May 02, 2011 6:07 pm

Re: Trying to recode a variable dependent on values in other

Postby apeape » Thu Feb 06, 2014 11:49 pm

First of all, it is bad practice to recode over your data. Recode into new variables rather than over existing variables.
gimmemoore wrote:I need to recode INTM (month of interview), only when it is 99, based on what is in RECD and RECM.

If RECD is less than 6, i need to recode INTM to one less than RECM (i.e. if the interview report form was received in the first five days of the month, then set the interview month to the previous month.)

If RECD is 6 or greater, i need to set INTM to the same as RECM (i.e. the interview form was received the same month the interview took place.)

Code: Select all

do if INTM = 99.
if (RECD lt 6) newINTM = RECM -1.
if (RECD ge 6) newINTM = RECM.
else.
compute newINTM = INTM.
end if.
exe.
gimmemoore
Posts: 2
Joined: Thu Feb 06, 2014 4:16 pm

Re: Trying to recode a variable dependent on values in other

Postby gimmemoore » Fri Feb 07, 2014 9:11 am

Hi apeape,

Thanks a lot, I have backup copies of the dataset so i don't mess up the original with my poor coding but i take your point that it's always worth computing a new variable when testing out these kinds of transformations.

It's just the phrasing and order of the syntax I have trouble with, still, practice makes perfect! :D

Who is online

Users browsing this forum: No registered users and 2 guests

cron