Creating "lagged" variables if you will...

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

curious_user
Posts: 2
Joined: Tue Sep 11, 2012 8:06 pm

Creating "lagged" variables if you will...

Postby curious_user » Tue Sep 11, 2012 8:18 pm

Hi, I'm not sure if this is the right forum to post this question, but I'm currently trying to create several new variables which will be binary coded. These variables will be named DIFF(i)_(j), where (i) and (j) are indexes, (j) is never greater than (i), and (i) = 1...12 and (j) = 1...11.

The current macro I'm using is the following:

DEFINE CREATE_VARS (arg1 = !tokens(1) /arg2 = !tokens(1))
!DO !i = 2 !to !arg1
!DO !j = 1 !to !arg2
IF !j < !i !concat("DIFF", !i, "_", !j) = 0.
IF !j < !i AND !concat("IMP",!i) >= !concat("IMP",!j) !concat("DIFF",!i,"_",!j) = 1.
!DOEND
!DOEND
!ENDDEFINE.

The issue is that variables DIFF2_2, DIFF2_3, ..., DIFF2_12, DIFF3_3, ..., DIFF11_12 are all created in the process and I don't want them to be. I tried to correct that with this syntax:

DEFINE CREATE_VARS (arg1 = !tokens(1) /arg2 = !tokens(1))
!DO !i = 2 !to !arg1
!DO !j = 1 !to !arg2
DO IF (!j < !i).
COMPUTE !concat("DIFF", !i, "_", !j) = 0.
END IF.
DO IF (!j < !i AND !concat("IMP",!i) >= !concat("IMP",!j)).
COMPUTE !concat("DIFF",!i,"_",!j) = 1.
END IF.
!DOEND
!DOEND
!ENDDEFINE.

But it resulted in the same outcome. Does anyone have any ideas on how to stop the creation of those unneeded variables? Thanks!
Penguin_Knight
Posts: 473
Joined: Thu Apr 05, 2012 5:58 pm

Re: Creating "lagged" variables if you will...

Postby Penguin_Knight » Tue Sep 11, 2012 10:30 pm

I can understand your syntax but I don't understand your motive. What are the actual variable(s) and what are you trying to create? In the topic you mention "lag," but I don't see any lagging in the macro.

Also, you mentioned there are a lot needless variables you'd like to get rid of, but could you also tell us what do you wish to keep?
curious_user
Posts: 2
Joined: Tue Sep 11, 2012 8:06 pm

Re: Creating "lagged" variables if you will...

Postby curious_user » Wed Sep 12, 2012 1:33 am

Penguin,

My motive is to create a bunch of variables to capture whether or not a respondent prefers one item over another. So, for example, the variable DIFF4_2 captures whether the respondent prefers Item 4 (DIFF4_2 = 1) or Item 2 (DIFF4_2 = 0), which is where the "IMP" & i > "IMP" & j comes in in the syntax.

Sorry for mentioning "lagged" variables in the heading. I seriously didn't know how else to reference the variables I'm trying to create. The variables I'm looking to keep are DIFF2_1, DIFF3_1, DIFF3_2, DIFF4_1, DIFF4_2, DIFF4_3, DIFF5_1, DIFF5_2, DIFF5_3, DIFF5_4, DIFF6_1, ... , DIFF12_11.

Please let me know if you have any other questions.

Who is online

Users browsing this forum: No registered users and 1 guest

cron