The codebook command was introduced in SPSS version 17. Itprovides information about the variables in a dataset, such as the type,variable labels, value labels, as well as the number of cases in each level ofcategorical variables and means and standard deviations of continuous variables.This information can be as important as the data themselves, because it helps togive meaning to the data. Also, this information can help you distinguishbetween two similar datasets.
The examples below will use the hs1.sav dataset.Let’s start by looking at the Variable View.
get file "D:\data\hsb1.sav".
You can access the codebook command via the point-and-click interface byclicking on Analyze -> Reports -> Codebook.
Let’s consider the syntax below. Although it may look complicated, onlythe command itself is necessary. If you issue the codebook commandby itself, you will get the variable information for all of the variables in thedataset; counts and percents for all categories of nominal and ordinalvariables; and means, standard deviations and quartiles for scale variables.This may be more output than you want, so you may prefer to select whichvariables and what information about them you would like to see. In theexample below, we have selected six variables from our dataset. In squarebrackets ( [] ) after each variable name, we have indicated the measurementlevel. Scale variables (AKA continuous variables) are indicates with an s, ordinal variables(AKA categorical variables)with an o, and nominal variables with an n. The measurementlevel specified in the command may or may not match that shown in the VariableView. For example, as we can see above, the variable socst has anominal measurement; however, in the codebook command below, we havespecified it as a scale variable. The type of measurement determines what willbe provided in the output for the variable: counts and percents for allcategories of nominal and ordinal variables; means, standard deviations andquartiles for scale variables.
On the varinfo subcommand, we request some of the information that we see inthe Variable View. On the fileinfo subcommand, we request information onthe data file itself, such as the name of the data file, its location, the filelabel, any documents attached to the data file and a count of the number ofcases in the dataset. On the statistics subcommand, we request the countand percent, which gives the number of cases and percent of cases in each levelof nominal and ordinal variables. We also request the mean and standarddeviation of scale variables.
codebook ses [o] prgtype write [s] science [s] socst [s] /varinfo position label type format measure valuelabels missing /fileinfo name location label documents casecount /statistics percent mean stddev.
In the example below, we show how to get minimal output (by using the keywordnone on the statistics subcommand), and ordering the output inalphabetical order (by using specifying varorder = alpha on the options subcommand).
codebook ses prgtype science socst /varinfo label type valuelabels /options varorder = alpha /statistics none.
For more information about documenting data in SPSS, please visitSPSS Learning Modules: Labeling and documentingdata andStatistical Consulting Seminars: Introduction to SPSS Syntax, Part 1 (section 13).