Compute new variable with Syntax

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Compute new variable with Syntax

Zhenling Jiang
Hello all,

I'm a newbie to SPSS Syntax, I'm trying to create a new variable that
can't be accomplished by point-and-click. Any suggestions and ideas are
welcomed!

To simplify the problem, I came up with an example like this:

Statement1 (which is 1-10 scale)
Statement2
Statement3
.....
Statement10

Each of the statement is a 1-10 scale question. If a person select top 3
box in Statement 1, he gets 3 points, middle 4 box gets 1 point and bottom
3 get 0. And it could be the other way around, let assume for Statement 3,
top 3 gets 0, middle 4 gets 1 and bottom 3 gets 3 points.

The new variable I'd like to compute is the sum of the points depending
how the respondents's answer.

I hope I made myself clear here. Look forward to a solution. Thanks!

Zhenling

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Compute new variable with Syntax

Art Kendall
Assuming that the variable named for each statement is the number of the
box was check something  try something like this untested syntax.
fixed font is best for looking at this syntax to see the vertically
parallel construction

numeric r_statement1 to r_statement10 (f2).
recode   statement1   statement2   statement5   statement6   statement10
(1 thru 3 = 3)(4 thru 7 =1)(8 thru 10=0)(else=copy) into
       r_statement1 r_statement2 r_statement5 r_statement6 r_statement10.
recode   statement3   statement4   statement7   statement8   statement9
(1 thru 3 = 0)(4 thru 7 =1)(8 thru 10=3)(else=copy) into
       r_statement3 r_statement4 r_statement7 r_statement8 r_statement9.
compute sum_score = sum(r_statement1 to r_statement10).

Art Kendall
Social Research Consultants

Zhenling Jiang wrote:

> Hello all,
>
> I'm a newbie to SPSS Syntax, I'm trying to create a new variable that
> can't be accomplished by point-and-click. Any suggestions and ideas are
> welcomed!
>
> To simplify the problem, I came up with an example like this:
>
> Statement1 (which is 1-10 scale)
> Statement2
> Statement3
> .....
> Statement10
>
> Each of the statement is a 1-10 scale question. If a person select top 3
> box in Statement 1, he gets 3 points, middle 4 box gets 1 point and bottom
> 3 get 0. And it could be the other way around, let assume for Statement 3,
> top 3 gets 0, middle 4 gets 1 and bottom 3 gets 3 points.
>
> The new variable I'd like to compute is the sum of the points depending
> how the respondents's answer.
>
> I hope I made myself clear here. Look forward to a solution. Thanks!
>
> Zhenling
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Compute new variable with Syntax

Zhenling Jiang
Thanks so much! The syntax works perfectly.

I have a small question: in the first statement " numeric r_statement1 to r_statement10 (f2).", what does the (f2) do?

Thanks again,

Zhenling

-----Original Message-----
From: Art Kendall [mailto:[hidden email]]
Sent: Thursday, December 11, 2008 5:25 PM
To: Jiang, Zhenling
Cc: [hidden email]
Subject: Re: Compute new variable with Syntax

Assuming that the variable named for each statement is the number of the
box was check something  try something like this untested syntax.
fixed font is best for looking at this syntax to see the vertically
parallel construction

numeric r_statement1 to r_statement10 (f2).
recode   statement1   statement2   statement5   statement6   statement10
(1 thru 3 = 3)(4 thru 7 =1)(8 thru 10=0)(else=copy) into
       r_statement1 r_statement2 r_statement5 r_statement6 r_statement10.
recode   statement3   statement4   statement7   statement8   statement9
(1 thru 3 = 0)(4 thru 7 =1)(8 thru 10=3)(else=copy) into
       r_statement3 r_statement4 r_statement7 r_statement8 r_statement9.
compute sum_score = sum(r_statement1 to r_statement10).

Art Kendall
Social Research Consultants

Zhenling Jiang wrote:

> Hello all,
>
> I'm a newbie to SPSS Syntax, I'm trying to create a new variable that
> can't be accomplished by point-and-click. Any suggestions and ideas are
> welcomed!
>
> To simplify the problem, I came up with an example like this:
>
> Statement1 (which is 1-10 scale)
> Statement2
> Statement3
> .....
> Statement10
>
> Each of the statement is a 1-10 scale question. If a person select top 3
> box in Statement 1, he gets 3 points, middle 4 box gets 1 point and bottom
> 3 get 0. And it could be the other way around, let assume for Statement 3,
> top 3 gets 0, middle 4 gets 1 and bottom 3 gets 3 points.
>
> The new variable I'd like to compute is the sum of the points depending
> how the respondents's answer.
>
> I hope I made myself clear here. Look forward to a solution. Thanks!
>
> Zhenling
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Compute new variable with Syntax

Art Kendall
You're welcome.   F2 is the display format to be used for this
variable.   Internally a number is stored to about 15 to 16 decimal
digits of accuracy.  When the display format has no decimal point and
number of decimal digits to display then the number is displayed as a
whole number. Since I thought your numbers went from 1 to 10, I told the
computer to allow 2 character spaces when displaying the number.


Art Kendall
Social Research Consultants

Jiang, Zhenling wrote:

> Thanks so much! The syntax works perfectly.
>
> I have a small question: in the first statement " numeric r_statement1 to r_statement10 (f2).", what does the (f2) do?
>
> Thanks again,
>
> Zhenling
>
> -----Original Message-----
> From: Art Kendall [mailto:[hidden email]]
> Sent: Thursday, December 11, 2008 5:25 PM
> To: Jiang, Zhenling
> Cc: [hidden email]
> Subject: Re: Compute new variable with Syntax
>
> Assuming that the variable named for each statement is the number of the
> box was check something  try something like this untested syntax.
> fixed font is best for looking at this syntax to see the vertically
> parallel construction
>
> numeric r_statement1 to r_statement10 (f2).
> recode   statement1   statement2   statement5   statement6   statement10
> (1 thru 3 = 3)(4 thru 7 =1)(8 thru 10=0)(else=copy) into
>        r_statement1 r_statement2 r_statement5 r_statement6 r_statement10.
> recode   statement3   statement4   statement7   statement8   statement9
> (1 thru 3 = 0)(4 thru 7 =1)(8 thru 10=3)(else=copy) into
>        r_statement3 r_statement4 r_statement7 r_statement8 r_statement9.
> compute sum_score = sum(r_statement1 to r_statement10).
>
> Art Kendall
> Social Research Consultants
>
> Zhenling Jiang wrote:
>
>> Hello all,
>>
>> I'm a newbie to SPSS Syntax, I'm trying to create a new variable that
>> can't be accomplished by point-and-click. Any suggestions and ideas are
>> welcomed!
>>
>> To simplify the problem, I came up with an example like this:
>>
>> Statement1 (which is 1-10 scale)
>> Statement2
>> Statement3
>> .....
>> Statement10
>>
>> Each of the statement is a 1-10 scale question. If a person select top 3
>> box in Statement 1, he gets 3 points, middle 4 box gets 1 point and bottom
>> 3 get 0. And it could be the other way around, let assume for Statement 3,
>> top 3 gets 0, middle 4 gets 1 and bottom 3 gets 3 points.
>>
>> The new variable I'd like to compute is the sum of the points depending
>> how the respondents's answer.
>>
>> I hope I made myself clear here. Look forward to a solution. Thanks!
>>
>> Zhenling
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>> [hidden email] (not to SPSSX-L), with no body text except the
>> command. To leave the list, send the command
>> SIGNOFF SPSSX-L
>> For a list of commands to manage subscriptions, send the command
>> INFO REFCARD
>>
>>
>>
>>
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Art Kendall
Social Research Consultants