SHAZAM Commands

SHAZAM Commands


Commands give instructions to SHAZAM. Commands tell SHAZAM to perform a certain task. Many SHAZAM commands also have options that instruct SHAZAM to perform additional tasks. Options are listed after a / character and can be specified in any order.

A complete description of SHAZAM commands is given in the SHAZAM User's Reference Manual.

Some important SHAZAM commands that are introduced here are:

An online reference guide to all SHAZAM commands is available.

Notes

  1. Commands and command options have names. Shortened names are allowed. For example, the SAMPLE command can be referred to as SAMP. On the READ command the SKIPLINES= option can be referred to as SKIP=.

  2. Commands can have continuation lines. If a command is terminated with the & character this indicates that the command is continued on the next line. An example of the use of continuation lines follows:
    READ (KLEIN.txt) WG T G TIME PLAG KLAG XLAG &
    C I W1 P WGWP X

  3. Variable name lists can be abbreviated by the use of a numbered range list. The variables in a numbered range list have the identical name, except for the last character or characters, which are consecutive numbers. For example, the following two commands are equivalent.
    STAT A1 A2 A3 A4 A5 A6

    STAT A1-A6

  4. In general, SHAZAM commands are not case sensitive. That is, upper case and lower case is interchangeable. However, if you wish to distinguish upper and lower case variables and file names in SHAZAM then use the command: SET NOLCUC.

Home [SHAZAM Guide home]

The SAMPLE command

The SAMPLE command sets the sample range of the data. The general command format is:

SAMPLE beg end

where beg and end are numbers specifying the beginning and ending observations to use for subsequent calculations.

Example
The Theil textile data set has 17 observations on each variable and so the SAMPLE command should be:

SAMPLE 1 17

To restrict the analysis to start in observation 3 and end in observation 14 the appropriate SAMPLE command is:

SAMPLE 3 14


back [Back to Top] Home [SHAZAM Guide home]

The READ command

The READ command loads the data set into SHAZAM memory and assigns variable names. The general command format is:

READ (filename) vars / options

where filename is the data filename, vars is a list of user assigned variable names, and options is a list of desired options. All the variables listed must have the same number of observations. Some useful options are:

BYVAR Read the data by variable. The data file must be prepared so that all observations for each new variable begin on a new line (more than 1 line can be used).
NOBYVAR Read the data by observation. The data file must be prepared so that observations for all variables begin on a new line (more than 1 line can be used). This is the default option.
LIST List all the data on the output file.
SKIPLINES=n   Skips the number of lines specified before reading data from the data file. This option is required when the data file contains a header of descriptive information.

Rules for preparing data files for SHAZAM can be viewed. Instructions are also available for working with Microsoft Excel XLS files.

Example 1 - Loading data from a data file
For the Theil textile data set each line of the data file contains one observation on the 4 variables. The following command assigns variable names and loads the data from the file THEIL.txt into SHAZAM memory.

SAMPLE 1 17
READ (THEIL.txt) YEAR CONSUME INCOME PRICE

The next command shows the use of the LIST option. This option instructs SHAZAM to list the data set on the output file. This can be very useful for checking that the data set has been read in correctly.

SAMPLE 1 17
READ (THEIL.txt) YEAR CONSUME INCOME PRICE / LIST

Example 2 - Small data sets - working without data files
Consider a data set with observations on height (inches) and weight (pounds) for 6 individuals (this example is from Chotikapanich and Griffiths, 1993). The data can be entered directly in the SHAZAM command file immediately following the READ command as follows.

SAMPLE 1 6
READ HEIGHT WEIGHT 
   69    112  
   56     84  
   62    102  
   67    135  
   70    165  
   63    120  

An alternative way of setting up the command file is to use the BYVAR option on the READ command as follows.

SAMPLE 1 6
READ HEIGHT WEIGHT / BYVAR
    69  56  62  67  70  63
  112  84  102  135  165  120

Another way of reading this simple data set is to use two READ commands (one for each variable) as follows.

SAMPLE 1 6
READ HEIGHT / BYVAR
    69  56  62  67  70  63
READ WEIGHT / BYVAR
  112  84  102  135  165  120


back [Back to Top] Home [SHAZAM Guide home]

The GENR command

The GENR command will create new variables from old ones and do a variety of data transformations. The general command format is:

GENR var=equation

where var is a user-assigned name of the variable to be generated and equation is an arithmetic expression which involves variables, scalars and mathematical functions.

The following mathematical operators may be used:

  1. unary functions (see list below)
  2. ** (exponentiation)
  3. * , / (multiplication, division)
  4. + , - (addition, subtraction)
  5. .EQ., .NE. , .GE. , .GT. , .LE. , .LT. (relational operators)
  6. .NOT. (logical operator)
  7. .AND. (logical operator)
  8. .OR. (logical operator)

The arithmetic expression that is given after the equal sign (=) is evaluated (any variable that is given in this expression must already exist). The result is saved in the variable that appears before the equal sign. If the result variable does not exist then SHAZAM will create it. If the result variable is already created then SHAZAM will replace the old variable with the new results.

On the GENR command arithmetic expressions are evaluated from left to right. However, some operators take priority. The order of operations conforms to the priority levels given above. Expressions in parentheses are always evaluated first. Therefore, to avoid confusion use as many levels of parentheses as desired.

The available unary functions are:

ABS(x) absolute value
DUM(x) dummy variable generator
EXP(x) exp(x)
INT(x) integer truncation
LAG(x) lag a variable one time period
LAG(x,n) lag a variable n time periods
LGAM(x) log gamma function
LOG(x) natural logs
MAX(x,y) maximum of two variables
MIN(x,y) minimum of two variables
MOD(x,y) modulo arithmetic, remainder of x/y
NCDF(x) standard normal cumulative distribution function
NOR(x) normal random number with standard deviation x
SAMP(x) draw a sample with replacement from the variable x
SEAS(x) seasonal dummy variable with periodicity x
SIN(x) sine (x measured in radians)
SIN(x,-1) arcsine (defined for x in the interval [-1,1])
SQRT(x) square roots
SUM(x) cumulative sum of variable x
SUM(x,n) sum of n observations on variable x starting at observation 1
TIME(x) time index plus x
UNI(x) uniform random number with range (0,x)


Example 1 - Computing a reciprocal
To compute the reciprocal of each observation in the variable A and save the result in the variable B the command to use is:

GENR B=1/A

Example 2 - Taking logarithms
When working with macroeconomic time series it is very common to use log-transformed variables in the analysis. To get the logarithm of each observation in the variable CONSUME and save the result in the new variable LCONS the command to use is:

GENR LCONS=LOG(CONSUME)

Example 3 - Computing a percentage change
To compute the percentage rate of change in the variable WAGE and save the results in the variable WR the command to use is:

GENR WR=100*(WAGE-LAG(WAGE))/LAG(WAGE)

Note that the LAG function is used to take a 1-period lag. This function must be used with some care. The first observation will be assigned to 0. Therefore, for subsequent analysis with the WR variable, the SAMPLE command must be set to start at observation number 2.

The same calculation can be done with two GENR commands as follows:

GENR LWAGE=LAG(WAGE)
GENR WR=100*(WAGE-LWAGE)/LWAGE

Example 4 - The exponentiation operator **
The command GENR E2=E**2 is the same as GENR E2=E*E
The command GENR SD=SQRT(VAR) is the same as GENR SD=VAR**(0.5)

More examples are in the SHAZAM User's Reference Manual.


back [Back to Top] Home [SHAZAM Guide home]

The GEN1 command

The GEN1 command is used for scalar arithmetic. The general command format is:

GEN1 var=equation

where var is a user-assigned name of the scalar variable to be generated and equation is an arithmetic expression. The GEN1 command is equivalent to using a SAMPLE 1 1 command with a GENR command to generate a variable with only 1 observation.

Example
To compute the logarithm of 2 pi and save the result in the variable L2PI the command to use is:

GEN1 L2PI=LOG(2*$PI)

Note the use of the variable $PI. In general, variables that start with a $ are special SHAZAM temporary variables. The SHAZAM variable $PI contains the value of pi set at 3.1415926535898. (On the SHAZAM output not all digits are printed).


back [Back to Top] Home [SHAZAM Guide home]

The PRINT command

The PRINT command is used to list variables on the SHAZAM output file. Note that this command does not direct output to the printer. The general command format is:

PRINT vars / options

where vars is a list of variable names and options is a list of desired options. Some useful options are:

BEG=   Specifies the first observation to be printed.
END=   Specifies the last observation to be printed.

If the above options are not used then the range set by the SAMPLE command is used.

Example
To list the variables in the Theil textile data set the command to use is:

PRINT YEAR CONSUME INCOME PRICE

To list the data on CONSUME and PRICE for the final 6 observations the command to use is:

PRINT CONSUME PRICE / BEG=12 END=17


back [Back to Top] Home [SHAZAM Guide home]

The WRITE command

The WRITE command is used to write variables to a file. The general command format is:

WRITE (filename) vars / options

where filename is the data filename, vars is a list of variable names, and options is a list of desired options. The available options on the WRITE command are similar to those available for the READ and PRINT commands.


back [Back to Top] Home [SHAZAM Guide home]

The SET command

The SET command is used to set options that affect the way SHAZAM does its work. The SET command has some useful options for controlling the amount of detail that appears on the output file. Some other uses of the SET command are contained in this guide.

In general, the format to turn on features is:

SET option

and the format to turn off features is:

SET NOoption

where option is the desired option. A complete description of available options is in the SHAZAM User's Reference Manual.


back [Back to Top] Home [SHAZAM Guide home]

The SKIPIF command

The SKIPIF command is used to specify conditions under which observations are to be skipped in subsequent SHAZAM commands. The general command format is:

SKIPIF (expression)

where the expression is an arithmetic expression as described for the GENR command. For each observation, the expression is evaluated and if the result is positive (or true) the observation is excluded from the sample. The expression may use the following relational operators.

Operator Meaning
  .EQ. Equal (=)
  .NE. Not Equal
  .GE. Greater than or equal
  .GT. Greater than (>)
  .LE. Less than or equal (LE)
  .LT. Less than (<)

Note that the operators must start and terminate with a dot (.). Upper case and lower case are interchangeable.

An example of the SKIPIF command is:

SKIPIF (XVAL .LE. 5.1)

The above command will skip observations when the value of the variable XVAL is less than or equal to 5.1.

Eliminating SKIPIF

After working with a sub-set of observations it may be useful to return to data analysis with the full sample. This can be done by eliminating all SKIPIF commands with the command:

DELETE SKIP$

Note that the $ character in SKIP$ is a special character for SHAZAM variable names.

SKIPIF Messages

The SKIPIF command lists the skipped observations on the SHAZAM output file. If a large number of observations have been skipped then the output listing can be lengthy. These messages can be suppressed by using the command:

SET NOWARNSKIP

More Documentation

More discussion on the use of the SKIPIF command is given in the SHAZAM User's Reference Manual.


back [Back to Top] Home [SHAZAM Guide home]

The STAT command

The STAT command is used to compute descriptive statistics (including mean, standard deviation, variance, minimum and maximum). The general command format is:

STAT vars / options

where vars is a list of variable names and options is a list of desired options. Some useful options are:

PCOR Prints a correlation matrix of the variables.
PCOV Prints a covariance matrix of the variables.
PMEDIAN Prints the median, mode, quartiles and interquartile range for each variable.
MEAN= Stores the means as a vector in the variable specified.
STDEV= Stores the standard deviations as a vector in the variable specified.
SUMS= Stores the sum of each variable as a vector in the variable specified.

Note that, in general, options that begin with the letter P are used to print results on the SHAZAM output file. Options ending in an = sign are used to save results in the variable specified.

Example
Consider the problem of finding the correlation between height and weight for a sample of 6 individuals. The SHAZAM commands below can be used to get the answer.

SAMPLE 1 6
READ HEIGHT WEIGHT / BYVAR
    69  56  62  67  70  63
  112  84  102  135  165  120
STAT HEIGHT WEIGHT / PCOR
STOP

The SHAZAM output follows:

|_SAMPLE 1 6
|_READ HEIGHT WEIGHT / BYVAR
   2 VARIABLES AND        6 OBSERVATIONS STARTING AT OBS       1

|_STAT HEIGHT WEIGHT / PCOR
NAME        N    MEAN        ST. DEV      VARIANCE     MINIMUM      MAXIMUM
HEIGHT        6   64.500      5.2440      27.500       56.000       70.000
WEIGHT        6   119.67      28.048      786.67       84.000       165.00

 CORRELATION MATRIX OF VARIABLES -        6 OBSERVATIONS

HEIGHT     1.0000
WEIGHT    0.81587       1.0000
             HEIGHT       WEIGHT
|_STOP

The output shows that the correlation between height and weight is: 0.81587.


back [Back to Top] Home [SHAZAM Guide home]

The STOP command

The STOP command is used to terminate the SHAZAM run. The format of the command is:

STOP


back [Back to Top] Home [SHAZAM Guide home]