An essay on syntax

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

An essay on syntax

Richard Ristow
Recently written to a student who's a user of the menus:


First, self-disclosure: I find syntax preferable for most purposes,
easy to write and easy to understand. BUT, that's after several
decades, literally, of writing and reading the stuff. Any programming
language can be maddeningly difficult to read or write, if you're not
familiar with it. They all have their quirks about how they express
common concepts, and struggling with those can obscure the substance
you're trying to understand.

And if you're not familiar with programming languages in any form, you
have another, more severe, layer of difficulty understanding one.

That said, syntax has inherent advantages. In an analogy, menus
(point-and-click) versus syntax is like the difference between spoken
and written natural language (which I'll write as 'English', to be
concise):

* There's much that you can express either way.
* It takes special effort and training to use written English (or
syntax) well. That's true for spoken English (point-and-click) as well,
but it's far easier to master the basics of speaking (or
point-and-click) well enough to use them.
* It's less work to express ideas, especially simple ideas, in speaking
(or point-and-click);
* However, it's more accurate, and often easier, to express complex
ideas in writing (or with syntax).
* What's written (or in syntax) is a record, and can be reread exactly
as written. (Spoken English can be recorded, but it's not often done.
Some point-and-click systems can record actions, but the recorded
format is usually awkward to read. (In that, SPSS is actually an
exception; see below.)
* Written English (and syntax) is far easier to revise, since the text
being revised can be reviewed at leisure, and text not changed can be
incorporated directly in the revision.

If you're going to use SPSS much, it's wise to learn at least some
syntax. (Learn it with a person who knows SPSS well, and who's good at
teaching. I don't know any book or books that do a good job for
somebody starting from scratch.)

As an illustration of its uses, perhaps you saw that the syntax I gave
you, and my explanation of how I'd edited it, were more compact and
more direct than my explanations of what I'd done with the menus. As
another, it is important to have the syntax for any transformations you
make on your data; otherwise, you can easily forget what you did, and
lose track of what your transformed data means.

And SPSS has an excellent, and very unusual, aid for learning syntax:
Most menu commands act by generating the corresponding syntax and
running it. It's like having everything you say transcribed for your
review - or even better, since the SPSS 'transcription' automatically
includes the special quirks of syntax. To see the syntax that's
generated, I recommend *all* of the following:

* Menu Edit > Options/General tab: Check 'Record syntax in journal' and
'Append'. That writes a transcript of all syntax run to a file, for
review. (To choose the file name and what directory it's in, click
"Browse".)
* Menu Edit > Options/General tab: Check 'Open syntax window at
start-up'. (It's in the lower left-hand corner).
* Menu Edit > Options/Viewer tab:  Check 'Display commands in log'.
* Menu Edit > Options/Draft Viewer tab: Check 'Display commands in
log'. (You probably won't use the Draft Viewer much, maybe not at all,
but you still might as well set this option, for completeness.)
* When you point-and-click something from the menus, occasionally end
by clicking 'Paste' instead of 'OK'. That will put the command in the
syntax window, where you can inspect it, edit it, and run it. (To run
syntax from a syntax window, put the cursor within the command or
select as many commands as you like; then, click the blunt right-arrow
on the control bar, or use menu 'Run'.)

=====================
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: An essay on syntax

Art Kendall
Well put!

I would add that:

Doing an analysis like any other creative process is a process of
continuous refinement.  As you grow in your understanding of your data
and of how to do analysis, you will refine what you want to do.

The menus are a great way to write the first drafts of portions of your
process. Since most of the menus are "sticky", you can keep going back
to the menu and choose or remove specifications.  When you are satisfied
for now click <paste>.

Having the syntax helps in many ways. You will inevitably be interrupted
during the development of your analysis.  Having the syntax saves you
from having to go through the whole process again.  The syntax
communicates what you are trying to do -- most of all to yourself, but
also to anyone who is trying to help you, to anyone doing quality
assurance review, and to anyone who is trying to replicate your research.


Art Kendall
Social Research Consultants


Richard Ristow wrote:

> Recently written to a student who's a user of the menus:
>
>
> First, self-disclosure: I find syntax preferable for most purposes,
> easy to write and easy to understand. BUT, that's after several
> decades, literally, of writing and reading the stuff. Any programming
> language can be maddeningly difficult to read or write, if you're not
> familiar with it. They all have their quirks about how they express
> common concepts, and struggling with those can obscure the substance
> you're trying to understand.
>
> And if you're not familiar with programming languages in any form, you
> have another, more severe, layer of difficulty understanding one.
>
> That said, syntax has inherent advantages. In an analogy, menus
> (point-and-click) versus syntax is like the difference between spoken
> and written natural language (which I'll write as 'English', to be
> concise):
>
> * There's much that you can express either way.
> * It takes special effort and training to use written English (or
> syntax) well. That's true for spoken English (point-and-click) as well,
> but it's far easier to master the basics of speaking (or
> point-and-click) well enough to use them.
> * It's less work to express ideas, especially simple ideas, in speaking
> (or point-and-click);
> * However, it's more accurate, and often easier, to express complex
> ideas in writing (or with syntax).
> * What's written (or in syntax) is a record, and can be reread exactly
> as written. (Spoken English can be recorded, but it's not often done.
> Some point-and-click systems can record actions, but the recorded
> format is usually awkward to read. (In that, SPSS is actually an
> exception; see below.)
> * Written English (and syntax) is far easier to revise, since the text
> being revised can be reviewed at leisure, and text not changed can be
> incorporated directly in the revision.
>
> If you're going to use SPSS much, it's wise to learn at least some
> syntax. (Learn it with a person who knows SPSS well, and who's good at
> teaching. I don't know any book or books that do a good job for
> somebody starting from scratch.)
>
> As an illustration of its uses, perhaps you saw that the syntax I gave
> you, and my explanation of how I'd edited it, were more compact and
> more direct than my explanations of what I'd done with the menus. As
> another, it is important to have the syntax for any transformations you
> make on your data; otherwise, you can easily forget what you did, and
> lose track of what your transformed data means.
>
> And SPSS has an excellent, and very unusual, aid for learning syntax:
> Most menu commands act by generating the corresponding syntax and
> running it. It's like having everything you say transcribed for your
> review - or even better, since the SPSS 'transcription' automatically
> includes the special quirks of syntax. To see the syntax that's
> generated, I recommend *all* of the following:
>
> * Menu Edit > Options/General tab: Check 'Record syntax in journal' and
> 'Append'. That writes a transcript of all syntax run to a file, for
> review. (To choose the file name and what directory it's in, click
> "Browse".)
> * Menu Edit > Options/General tab: Check 'Open syntax window at
> start-up'. (It's in the lower left-hand corner).
> * Menu Edit > Options/Viewer tab:  Check 'Display commands in log'.
> * Menu Edit > Options/Draft Viewer tab: Check 'Display commands in
> log'. (You probably won't use the Draft Viewer much, maybe not at all,
> but you still might as well set this option, for completeness.)
> * When you point-and-click something from the menus, occasionally end
> by clicking 'Paste' instead of 'OK'. That will put the command in the
> syntax window, where you can inspect it, edit it, and run it. (To run
> syntax from a syntax window, put the cursor within the command or
> select as many commands as you like; then, click the blunt right-arrow
> on the control bar, or use menu 'Run'.)
>
> =====================
> 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
|

Case to Variables (again!)

Tuerk, Elena
In reply to this post by Richard Ristow
Hi Richard and other listers,

I have one more case to variables question:

Once you've restructured data and want to do something easy like compute
a mean, is there a shorthand for the following?

COMPUTE MEANRBT = MEAN(RBTITEM.1, RBTITEM.2, RBTITEM.3, RBTITEM.4,
RBTITEM.5, RBTITEM.6, RBTITEM.7, RBTITEM.8, RBTITEM.9, RBTITEM.10,
RBTITEM.11, RBTITEM.12, RBTITEM.13, RBTITEM.14, RBTITEM.15, RBTITEM.16,
RBTITEM.17) .
EXECUTE .

For example, is there some way to do the following (which doesn't work),
so that it takes the mean of all items with that prefix?

COMPUTE MEANRBT = MEAN(RBTITEM) .
EXECUTE .

Best,

Elena

=====================
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: Case to Variables (again!)

Richard Ristow
At 02:57 PM 10/17/2007, Elena Tuerk wrote:

>Once you've restructured data and want to do something easy like
>compute a mean, is there a shorthand for the following?
>
>COMPUTE MEANRBT = MEAN(RBTITEM.1, RBTITEM.2, RBTITEM.3, RBTITEM.4,
>RBTITEM.5, RBTITEM.6, RBTITEM.7, RBTITEM.8, RBTITEM.9, RBTITEM.10,
>RBTITEM.11, RBTITEM.12, RBTITEM.13, RBTITEM.14, RBTITEM.15,
>RBTITEM.16,
>RBTITEM.17) .
>
>For example, is there some way to do the following (which doesn't
>work), so that it takes the mean of all items with that prefix?
>
>COMPUTE MEANRBT = MEAN(RBTITEM) .

Would 'twere so!

With some moderately ambitious Python, you could generate the COMPUTE
statement above. But I'd really compute the mean *before*
restructuring:
|-----------------------------|---------------------------|
|Output Created               |17-OCT-2007 15:20:30       |
|-----------------------------|---------------------------|
PtcptID Item RBTITEM

   101     1      4
   101     2      3
   101     3      3
   101     4      1
   102     1      1
   102     2      5
   103     1      1
   103     2      4
   104     1      3
   104     2      2
   105     1      4

Number of cases read:  11    Number of cases listed:  11


*  ....   Now, use AGGREGATE to compute the mean   ..... .
*  ....   Syntax clicked up from DATA > AGGREGATE  ..... .

AGGREGATE
   /OUTFILE=*
   MODE=ADDVARIABLES
   /BREAK=PtcptID
   /RBTITEM_mean = MEAN(RBTITEM).

LIST.
|-----------------------------|---------------------------|
|Output Created               |17-OCT-2007 15:25:03       |
|-----------------------------|---------------------------|
PtcptID Item RBTITEM RBTITEM_mean

   101     1      4         2.75
   101     2      3         2.75
   101     3      3         2.75
   101     4      1         2.75
   102     1      1         3.00
   102     2      5         3.00
   103     1      1         2.50
   103     2      4         2.50
   104     1      3         2.50
   104     2      2         2.50
   105     1      4         4.00


Number of cases read:  11    Number of cases listed:  11


*  ....   And, restructure using CASESTOVARS       ..... .
*  ....   Syntax clicked up                        ..... .
*  ....   Neither RBTITEM nor RBTITEM_mean are to  ..... .
*  ....   be mentioned *anywhere* in the wizard.   ..... .

SORT CASES BY PtcptID Item .
CASESTOVARS
  /ID = PtcptID
  /INDEX = Item
  /GROUPBY = VARIABLE .

Cases to Variables
|-----------------------------|---------------------------|
|Output Created               |17-OCT-2007 15:29:10       |
|-----------------------------|---------------------------|
Generated Variables
|--------|----|---------|
|Original|Item|Result   |
|Variable|    |---------|
|        |    |Name     |
|--------|----|---------|
|RBTITEM |1   |RBTITEM.1|
|        |2   |RBTITEM.2|
|        |3   |RBTITEM.3|
|        |4   |RBTITEM.4|
|--------|----|---------|

Processing Statistics
|---------------|---|
|Cases In       |11 |
|Cases Out      |5  |
|---------------|---|
|Cases In/Cases |2.2|
|Out            |   |
|---------------|---|
|Variables In   |4  |
|Variables Out  |6  |
|---------------|---|
|Index Values   |4  |
|---------------|---|


LIST.

List
|-----------------------------|---------------------------|
|Output Created               |17-OCT-2007 15:29:10       |
|-----------------------------|---------------------------|
PtcptID RBTITEM_mean RBTITEM.1 RBTITEM.2 RBTITEM.3 RBTITEM.4

   101         2.75        4         3         3         1
   102         3.00        1         5         .         .
   103         2.50        1         4         .         .
   104         2.50        3         2         .         .
   105         4.00        4         .         .         .

Number of cases read:  5    Number of cases listed:  5

===================
APPENDIX: Test data
===================
INPUT PROGRAM.
SET RNG = MT       /* 'Mersenne twister' random number generator  */ .
SET MTINDEX = 143  /* Random page in a book */.
.  NUMERIC PtcptID (F3)
           /Item    (F2).
.  LEAVE   PtcptID.
.  NUMERIC RBTITEM (F2).
.  LOOP    PtcptID = 101 TO 105.
.     LOOP Item = 1 TO 5.
.        COMPUTE RBTITEM = TRUNC(RV.UNIFORM(1,6)).
.        END CASE.
.     END LOOP IF RV.BERNOULLI(0.1).
.  END LOOP.
END FILE.
END INPUT PROGRAM.

LIST.

=====================
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: Case to Variables (again!)

Albert-Jan Roskam
In reply to this post by Tuerk, Elena
Hi Elena,

compute meanrbt = mean (rbtitem.1 to rbtitem.17).

But be aware of missing values (see a question from me
from a couple of days ago, answered by Gene and Jon).

Albert-Jan

--- Elena Tuerk <[hidden email]> wrote:

> Hi Richard and other listers,
>
> I have one more case to variables question:
>
> Once you've restructured data and want to do
> something easy like compute
> a mean, is there a shorthand for the following?
>
> COMPUTE MEANRBT = MEAN(RBTITEM.1, RBTITEM.2,
> RBTITEM.3, RBTITEM.4,
> RBTITEM.5, RBTITEM.6, RBTITEM.7, RBTITEM.8,
> RBTITEM.9, RBTITEM.10,
> RBTITEM.11, RBTITEM.12, RBTITEM.13, RBTITEM.14,
> RBTITEM.15, RBTITEM.16,
> RBTITEM.17) .
> EXECUTE .
>
> For example, is there some way to do the following
> (which doesn't work),
> so that it takes the mean of all items with that
> prefix?
>
> COMPUTE MEANRBT = MEAN(RBTITEM) .
> EXECUTE .
>
> Best,
>
> Elena
>
> =====================
> 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
>


Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of results that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

=====================
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: Case to Variables (again!)

Melissa Ives
In reply to this post by Tuerk, Elena
Well, that assumes that the rbitems are consecutive in the dataset.  If
they are, then great!
You can specify a 'minimum number of valid items' needed to calculate a
mean by using something like (in this example 10 valid items are
required to calculate a mean).

        compute meanrbt = mean.10(rbtitem.1 to rbtitem.17).

Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Albert-jan Roskam
Sent: Wednesday, October 17, 2007 2:34 PM
To: [hidden email]
Subject: Re: [SPSSX-L] Case to Variables (again!)

Hi Elena,

compute meanrbt = mean (rbtitem.1 to rbtitem.17).

But be aware of missing values (see a question from me from a couple of
days ago, answered by Gene and Jon).

Albert-Jan

--- Elena Tuerk <[hidden email]> wrote:

> Hi Richard and other listers,
>
> I have one more case to variables question:
>
> Once you've restructured data and want to do something easy like
> compute a mean, is there a shorthand for the following?
>
> COMPUTE MEANRBT = MEAN(RBTITEM.1, RBTITEM.2, RBTITEM.3, RBTITEM.4,
> RBTITEM.5, RBTITEM.6, RBTITEM.7, RBTITEM.8, RBTITEM.9, RBTITEM.10,
> RBTITEM.11, RBTITEM.12, RBTITEM.13, RBTITEM.14, RBTITEM.15,
> RBTITEM.16,
> RBTITEM.17) .
> EXECUTE .
>
> For example, is there some way to do the following (which doesn't
> work), so that it takes the mean of all items with that prefix?
>
> COMPUTE MEANRBT = MEAN(RBTITEM) .
> EXECUTE .
>
> Best,
>
> Elena
>
> =====================
> 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
>


Cheers!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Did you know that 87.166253% of all statistics claim a precision of
results that is not justified by the method employed? [HELMUT RICHTER]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

=====================
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


PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

=====================
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: An essay on syntax

Kaeleen Dingle
In reply to this post by Richard Ristow
Thanks for the hints. I have been 'copying and pasting' my syntax and then
manipulating it but I end up with very long and potentially confusing long
files, especially for Log regression etc.
I am very keen to learn more syntax and have not found any books that
help. Could you recommend any beginner (no programming background!) syntax
user websites or books or manuals?
Thanks

=====================
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: An essay on syntax

ViAnn Beadle
Have you looked at Help? The quickest way to get to the help on syntax for a
command is to put the cursor on the command in a syntax window and press F1.
I'd venture to guess that most books that are syntax oriented are usually
oriented towards data management with SPSS rather than statistical analysis.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Kaeleen Dingle
Sent: Wednesday, October 17, 2007 6:00 PM
To: [hidden email]
Subject: Re: An essay on syntax

Thanks for the hints. I have been 'copying and pasting' my syntax and then
manipulating it but I end up with very long and potentially confusing long
files, especially for Log regression etc.
I am very keen to learn more syntax and have not found any books that
help. Could you recommend any beginner (no programming background!) syntax
user websites or books or manuals?
Thanks

=====================
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: An essay on syntax

Jason Burke
I might add that, in my opinion, SPSS 16.0 has taken a great leap
forward. The command syntax generated by the user interface now
consistently follows a rule commencing subcommands on new lines! On
the GET DATA command the command terminator immediately follows the
last subcommand :-)

Reviewing, and editing (UI generated) command syntax is far easier for
exisiting and new users alike. One small step for SPSS, one huge
benefit for users!




On 10/18/07, ViAnn Beadle <[hidden email]> wrote:

> Have you looked at Help? The quickest way to get to the help on syntax for a
> command is to put the cursor on the command in a syntax window and press F1.
> I'd venture to guess that most books that are syntax oriented are usually
> oriented towards data management with SPSS rather than statistical analysis.
>
>
> -----Original Message-----
> From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
> Kaeleen Dingle
> Sent: Wednesday, October 17, 2007 6:00 PM
> To: [hidden email]
> Subject: Re: An essay on syntax
>
> Thanks for the hints. I have been 'copying and pasting' my syntax and then
> manipulating it but I end up with very long and potentially confusing long
> files, especially for Log regression etc.
> I am very keen to learn more syntax and have not found any books that
> help. Could you recommend any beginner (no programming background!) syntax
> user websites or books or manuals?
> Thanks
>
> =====================
> 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